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

Discussion

Discussion

New Designer Javascript

posted on March 17

I have a radio button with Yes and No. And a dropdown field. I have this javascript when Yes is selected then the dropdown should be filled with TMHP and nothing should happen when No is selected. I tried this  LFForm.setFieldValues({fieldId: 77},'TMHP'); on the outside of the If statement and the field does get populated with TMHP. However, when it is inside the If statement it will not work. Below is my code.

 

 

LFForm.onFieldChange(function() {
    if (LFForm.getFieldValues({ fieldId: 146}) === 'Yes') {
      LFForm.setFieldValues({fieldId: 77},'TMHP');
    } else {
    }
}, { fieldId: 146 });

0 0
replied on March 18 Show version history

Nice, thanks

So this is what I came up with and it works.

LFForm.onFieldChange(function() {
    const fieldValue = LFForm.getFieldValues({ fieldId: 146 }).value;
    if (fieldValue === 'Yes') {
        LFForm.setFieldValues({ fieldId: 77 }, 'TMHP');
    } else if (fieldValue === 'No') {
        LFForm.setFieldValues({ fieldId: 77 }, '');
    }
}, { fieldId: 146 });
1 0
replied on March 18
LFForm.getFieldValues({ fieldId: 146})

is returning an object. From that object, you need to extract the string value you want:

LFForm.getFieldValues({ fieldId: 146}).value

 

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

Sign in to reply to this post.