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

Question

Question

initialize dropdown field

asked on September 29

Hello everyone. Could you help me with this form issue to initialize a dropdown field? In the classic version of the form, a statement similar to $('#q17 option').remove(); is used in JavaScript to delete all entries. However, in the new form, I can't find a statement that allows (initializing) deleting all entries in the field. There are only the add, replace, and remove options (the latter for each entry).
Is there another method?

0 0

Replies

replied on October 1

I didn't test either of these idea, but...

 

I believe the Replace option with an empty array should do it.

LFForm.changeFieldOptions( { fieldId: 17 }, [], "replace" );

 

If that doesn't work, you could try replacing it with a single value and then deleting that value.

async function clearDropdown() {
  await LFForm.changeFieldOptions( { fieldId: 17 }, [{label: "New Label", value: "Choice_1"}], "replace" );
  LFForm.changeFieldOptions( { fieldId: 17 }, [{label: "New Label"], "remove" );
}
clearDropdown();

 

Once again, I didn't test either of those code samples, I don't think I've ever had a need to completely clear every option from a drop-down field.

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

Sign in to reply to this post.