Can I use visibility rules with user group?

  • 5uwebsite
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 108
  • Thank you received: 2

5uwebsite replied the topic: Can I use visibility rules with user group?

Hi Mihaela,

Thank you for your reply.

I deleted the hidden input element of User Group ID, and created another one of text-field type.

I tested it and it displays the field but it is wired that you need to click on the "usergroupid" text field first then the corresponding field (Used_or_Leased, Certificated_or_show) will come out.

Yet, If you dont click the "usergroupid" text field even you have the correct usergroupid, the corresponding field wont display.

Here is the screenshot's link : drive.google.com/file/d/1wpBwieIEKWAEu7f0HtTS7qwhh_ZUtqlL/view

Why is this happening? and How to solve it?


Thank you for your patient.
#233504
  • Posts: 1740
  • Karma: 62
  • Thank you received: 217

mihaela replied the topic: Can I use visibility rules with user group?

Hello again,

Did you login with an account of user from group 10 or 11? If you have, the corresponding field should be shown as soon as the form is entered.
I've tested it once more at my site and it is working properly for me.

I've tried to test it myself, but I can't since id of the group I was assigned to is 2.

I will try to explain why visibility rules work in a way that you've written in previous post. After you enter a value in a textfield it is needed that you click anywhere else on the form so that visibility rules are triggered. It is set to work this way because otherwise there is no way to know that user is done with his entry in that textfield.

Despite that, in your case it should work, because the id shouldn't be entered manually, but it should be collected before form, because the code for that is in "Before From".

If showing/hiding fields for some reason still doesn't work (after you've logged in with account from usergroup 10 ow 11), you can add JavaScript visibility rules to the Initialization script I've suggested you in the other ticket.

The code would go like this:
 if(ff_getElementByName('usergroupid').value == "10")  {
     bfToggleFields('on', 'element','Used_or_Leased' , bfDeactivateField);
     bfToggleFields('off', 'element','Certificated_or_show' , bfDeactivateField);     
}
 else if(ff_getElementByName('usergroupid').value == "11")  {
     bfToggleFields('on', 'element','Certificated_or_show' , bfDeactivateField);
     bfToggleFields('off', 'element','Used_or_Leased' , bfDeactivateField);     
}
else {
     bfToggleFields('off', 'element','Used_or_Leased' , bfDeactivateField);
     bfToggleFields('off', 'element','Certificated_or_show' , bfDeactivateField);     
}

Let me know whether this resolves the problem.

Regards,

Mihaela
#233525
  • 5uwebsite
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 108
  • Thank you received: 2

5uwebsite replied the topic: Can I use visibility rules with user group?

Hi Mihaela,

Thank you for your reply and help.

I placed the code you gave it to me, and removed the visibility rule.

Also, I tested with two users that are in different user groups (10 and 11).

But, the user in user group 10 works which display the corresponding field but the user in user group 11 does not work.

However, I checked the user make sure it is user group 11. Also, I created a new user that is in user group 11. But still not working. The "Certificated_or_show" is not displayed when user group 11's user login.

Here are the screenshot's links:

mrkr.io/s/5c489f82031fa50e1c78b780/0

mrkr.io/s/5c48a4838f04c80de5b3accb/0

Thanks A LOT!
#233546
  • 5uwebsite
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 108
  • Thank you received: 2

5uwebsite replied the topic: Can I use visibility rules with user group?

Hi Mihaela,

I found out why the user (who is in usergroup 11) does not work.

The reason is the user belongs to more than one group. For example, the user not only belongs to usergroup 11 also in usergroup 6. That's why doesnt not display the corresponding field in the form.

However, thank you Mihaela for all your support!
#233547
  • Posts: 1740
  • Karma: 62
  • Thank you received: 217

mihaela replied the topic: Can I use visibility rules with user group?

Hello again,

I'm glad to help you.
I think that fact that user belongs to more than one user group is the key to solve this.
That is the reason the suggested solution didn't work.

Here is the code for Before Form pieces that you should use which will work for cases when user belongs only to one of groups 10 or 11, or to one of this groups and some other group as well (for example 6 and 11).
$this->execPieceByName('ff_InitLib');

$user = JFactory::getUser(); 
$user_id ="$user->id"; 

if($user_id == '0' ) {
    $group_id = 0;
    }
else {
    $db = JFactory::getDBO();
    $db->setQuery("SELECT group_id FROM #__user_usergroup_map WHERE user_id =". $user_id);
    $group_ids = $db->loadColumn(); 

   if(count($group_ids) == "1") {
    $group_id = $group_ids[0];
    }
  else {
  $group_id = "";
  foreach ($group_ids as $ids) {
    if($ids == "10") {
    $group_id = 10;  }
    if($ids == "11") {
    $group_id = 11; }
    if($ids == "") {
    $group_id = 0; }
}

  }

 }

ff_setValue('usergroupid', $group_id);

Let me know whether this resolved the problem.

Regards,

Mihaela
#233563
  • 5uwebsite
  • Topic Author
  • Offline
  • Expert Boarder
  • Expert Boarder
  • Posts: 108
  • Thank you received: 2

5uwebsite replied the topic: Can I use visibility rules with user group?

Hi Mihaela,

Thank you!

I replaced the code and it works well. Even a user belongs in one than one group.

Thank a lot for all your help and support!

Best Regards,
#233587
Moderators: ForumSupporttomeperica
Time to create page: 0.078 seconds

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99€

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here