Toggle menu

Hiding Fields by User or User Group

This example loads a user's profile, checks the groups they are in, then uses a conditional layout to hide fields from users not in the staff group. You can download a copy of the form from the downloads area.

Load the Profile

The standard User Profile field returns the groups a user is in. There's no need to return any other profile elements or make them available browser-side.

Load User Profile
 

Save the Groups

The information returned by the User Profile field won't be available when the form is submitted. So that you can control the conditional field server-side (if you are saving data or sending emails for example) it's best to save the information you need in a hidden input field. This default function will save the groups a user is in as the value of the hidden field:

Save Groups
 

The groups a user is in are returned as an object where the keys are group names and values group IDs. This user is in two groups:

"groups": {
    "STAFF": 4,
    "ICMSITEUSER": 9
}

The Condition Function

Conditional layout fields are evaluated as the HTML of the page is being generated. Unlike showing and hiding fields, they are completely removed from the form (if their condition function returns false), not just hidden.

This function removes the fields in the layout by default, and will only include them if the user is in the STAFF group:

function(helper) {
    var showFields;
    showFields = false;
    if (helper.getFieldValue("GROUPS").hasOwnProperty("STAFF")) {
        showFields = true;
    }
    return showFields;
}

Any number of fields can be placed in your conditional layout and you can include any number of conditional layouts on the same form.

Last modified on November 11, 2022

Share this page

Facebook icon Twitter icon email icon

Print

print icon