Hide a Field by Default

Hi,

How can I hide a Field by default when the form has loaded and make it appear only when a condition has passed.

I want the 'Is employee terminating assignment' to be hidden by default when the form first loads. IF the first question is answered 'Yes' then i want the second drop down to appear.

image

Thank you!

Hello @Qman,

Please find the code sample in our documentation here:
https://plumsail.com/docs/forms-sp/how-to/conditional-fields.html#hide-show-field

Hi @mnikitina,

I have used the examples you have provided but I don't get the outcome I expect.

The 'is the employee terminating one of their assignments' is still visible on form load. I want it to be hidden on form load and then appear if a User selects a Yes/No answer.

I am currently using this code:

//Show/Hides Terminating Assignment Field & More Information Button - [Wizard 1]
fd.spRendered(function() {

function hideOrShowDueDate() {
    if (fd.field('Is_x0020_the_x0020_employee_x0020').value == 'Yes') {
        // Hide Terminating Assignment Field and More information button
        $(fd.field('Is_x0020_the_x0020_Employee_x002').value = 'No');
        $(fd.field('Is_x0020_the_x0020_Employee_x002').$parent.$el).hide();
        $('.Term-button').hide();
    } else {
        // Show the field
        $(fd.field('Is_x0020_the_x0020_Employee_x002').$parent.$el).show();
        $('.Term-button').show();
    }
}

// Calling hideOrShow when the EmployeeIsLeaving value changes
fd.field('Is_x0020_the_x0020_employee_x0020').$on('change',hideOrShowDueDate);

// Calling hideOrShowDueDate on form loading
hideOrShowDueDate();

});

Hello @Qman,

Your code has an invalid line that breaks the code:

$(fd.field('Is_x0020_the_x0020_Employee_x002').value = 'No');

Remove it and test the code.

Hi @mnikitina, I actually need this code to populate in another field otherwise the error message will interfere with the user experience.

@Qman,

To set the field value, you don't need to call the jQuery library with $. Use this code:

fd.field('Is_x0020_the_x0020_Employee_x002').value = 'No';
1 Like