Hide fields based on selections

Hi,

I am trailing this software and its great so far, but im struggling to hide fields based on selections.

i have a list which is lots of choice fields with 3 options yes/no/na

i want to show more of the questions based on the choices of the questions.

i have tried some of the js code but im getting no where… here is the code i added please tell me where im going wrong.

fd.spRendered(function() {

function toggleAuditResignationField() {

var auditClientStatus = fd.field('Aretheyanauditclient').value;

// Show the field only if "Yes" is selected

if (auditClientStatus === 'Yes') {

fd.field('Auditresignationlettersent_x003f').visible = true;

} else {

fd.field('Auditresignationlettersent_x003f').visible = false;

}

}

// Run on form load

toggleAuditResignationField();

// Run when the choice changes

fd.field('Aretheyanauditclient').$on('change', toggleAuditResignationField);

});

thanks

ben

Hello @Ben_Page,

Welcome to Plumsail Community!

The code looks valid. Are you getting any errors in the browser console when loading the form? Could you please share the screenshot.

And also share the export of the form.

Hi @Ben_Page ,

just saw your issue. We only use “fd.field('Field1').hidden = true/false;” for fields and had no issues so far - as Choice — Plumsail SharePoint Forms Documentation .

// hide field
fd.field('Field1').hidden = true;

// show field
fd.field('Field1').hidden = false;

Sometimes you have to use, e.g. for controls:

// show
$(fd.control('Text1').$el).show();

// hide
$(fd.control('Text1').$el).hide();

Maybe try to use:

fd.spRendered(function () {

    function toggleAuditResignationField() {

        var auditClientStatus = fd.field('Aretheyanauditclient').value;

        // Show the field only if "Yes" is selected

        if (auditClientStatus === 'Yes') {

            fd.field('Auditresignationlettersent_x003f').hidden = true;

        } else {

            fd.field('Auditresignationlettersent_x003f').hidden = false;
        }

    }

    // Run on form load
    toggleAuditResignationField();

    // Run when the choice changes

    fd.field('Aretheyanauditclient').$on('change', toggleAuditResignationField);

});

An example we use regularly:

function showHideFields() {
    if (fd.field('Field1').value == 'Yes') {
        fd.field('Field2').hidden = false; //Works for e.g. single line text
        $(fd.control('Text1').$el).show(); //Works for some other field types just try which works for you
    } else {
        fd.field('Field2').hidden = true;
        $(fd.control('Text1').$el).hide();
    }
}

fd.spRendered(function () {

    showHideFields();
    fd.field('Field1').$on('change', showHideFields);
    
});

Hope this helps.

All the best,

Felix