How to hide fields according to the role of the user?

Created on 5 December 2022, over 1 year ago
Updated 14 May 2024, about 1 month ago

Problem/Motivation

Hello,
I have the "intern" role, I would like to hide some fields depending on the role of the user's account.
But when I try to set the condition, it doesn't work.

Steps to reproduce

Entity Type : User

Target field : field_custom
Controlled by : roles
The target field is : Invisible
When the control field : value
Values input mode : Regular Expression
Regular expression : ^.*intern.*$

💬 Support request
Status

Needs work

Version

4.0

Component

User interface

Created by

🇬🇵Guadeloupe Monster971

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • 🇮🇳India arunkumark Coimbatore

    Am also facing the same problem when using the Conditional fields with the User account form. After some debugging, I found the reason the Roles, Name, and Email fields are part of the field parent account associate array coming from the core.

    Remaining task:
    The patch still needs some work to populate the selected value and testing.

  • Status changed to Needs work over 1 year ago
  • @arunkumark opened merge request.
  • 🇮🇳India arunkumark Coimbatore

    Initial patch for resolve parent fields.

  • 🇺🇸United States W01F

    Testing patch - widget now correctly shows fields, but the values aren't retained when hitting save.

    Example - set Roles as dependency
    1. Select a few roles in the widget
    2. Hit save
    3. Edit the same condition
    4. Previously selected roles are still unchecked

  • 🇸🇰Slovakia erik_petra

    I'm changing this to Major, as it affects core functionality.

    The workaround I had to do was to create a new role placeholder field as entity reference to roles, hide the original field, and fill the original one in the form submit hook. Presave could work too.

    Then I used the new role placeholder field with conditional logic to make things work.

Production build 0.69.0 2024