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

Question

Question

New forms designer enable or disable a field based on another field value

asked on September 18, 2024

I would like (in the new forms designer) to enable and disable a field based on another fields value as it changes.  This is what I am starting with and it isn't working:

 

LFForm.onFieldChange(() => console.log("change"), {fieldID:8});
{
  if(LFForm.getFieldValues({fieldID: 8}) === "1") 
  {
    LFForm.disalbeFields({fieldID: 6});
  }
  {LFForm.eanbleFields({fieldId: 6});
  }
});

Help?

0 0

Answer

SELECTED ANSWER
replied on September 18, 2024

You can use the Field Rules for this in Modern.  Here is an example of the setup:

 

1 0

Replies

replied on September 19, 2024

Field rules are definitely the easiest way forward here, but for completion sake the correct code is below. You had a few spelling mistakes on the enable/disable fields functions and only the "I" in fieldId should be capitalized.

LFForm.onFieldChange(
  () => {
    if (LFForm.getFieldValues({ fieldId: 8 }) === '1') {
      LFForm.disableFields({ fieldId: 6 });
    }
    {
      LFForm.enableFields({ fieldId: 6 });
    }
  },
  { fieldId: 8 },
);

 

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

Sign in to reply to this post.