You are viewing limited content. For full access, please sign in.

Question

Question

JavaScript add value to dropdown

asked on February 27

I am trying to replace the values in a dropdown based on the current step value. At the moment, I have the {/_current_step_name} set as a default value in a temporarily unhidden single line field.

LFForm.onFieldChange(function() {
  var mNum = LFForm.getFieldValues({fieldId: 63});
  if (mNum.match(/.*Probation.*/))
    LFForm.changeFieldOptions( { fieldId: 40 }, [{label: "Current"},{label: "Ending Employment"}], "replace" );
}, {fieldId: 63});

This works if I manually change the field 63 value. However, I would like the change to happen when the form loads. Can this be done?

I have been going over these forums for hours :)

Forms 12

0 0

Replies

replied on February 28

I'm not sure what the function's dependency on "mNum" is because you aren't removing anything from the dropdown if it doesn't contain probation. Assuming this is missing business logic and the function doesn't need to only be fired a single time, you can just extract the callback and use it on load and on field change.

const updateProbationDropdown = async () => {
    var mNum = LFForm.getFieldValues({fieldId: 63});
    if (mNum.match(/.*Probation.*/)) {
       await LFForm.changeFieldOptions( { fieldId: 40 }, [{label: "Current"},{label: "Ending Employment"}], "replace" );
    } else {
        // do stuff when it is not probation

    }
}

// Check on change
LFForm.onFieldChange(updateProbationDropdown, {fieldId: 63});

// Check on form load
updateProbationDropdown()

 

1 0
replied on February 28

It looks like you're using Modern Designer. This documentation shows the events you can use as triggers.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.