• Resolved joncon62

    (@joncon62)


    I want to be able to set a dropdown option using the js API. If my Dropdown has labels and values of ‘one’,1 ‘two’,2 ‘three’,3 etc I can read the selected option using

    LoadedForms[0].GetFieldById(27).GetText();

    So if ‘three’ was selected then the above function returns ‘three’. But how do I set a selected dropdown value based on the text, eg I want to set it to say ‘two’. I tried

    LoadedForms[0].GetFieldById(27).SetText('two');

    but this is not a supported function.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author EDGARROJAS

    (@edgarrojas)

    To set an id of a dropdown you need t o use the SetSelection method which expect and array of the ids of the options to select. So you first need to find the id of the option that you want to select, the dropdown also has a field called OptionItemsToUse that has all the options of the dropdown. So you need to use this array to find the id of the option that you want to use, something like this:

    var option id=LoadedForms[0].GetFieldById(3).OptionItemsToUse.find(x=>x.Label=="Option 1").Id

    then after having the id of the option you just need to use the set selection as explained. Here is the full code for selecting the option with label “Option 1”

    var field=LoadedForms[0].GetFieldById(3);
    var fieldId=field.OptionItemsToUse.find(x=>x.Label=="Option 1").Id;
    field.SetSelection([fieldId])

    Regards!

    Thread Starter joncon62

    (@joncon62)

    Thank you, works perfectly!

    Plugin Author EDGARROJAS

    (@edgarrojas)

    Great!

    Let me know if you have any other questions or suggestions for the plugin. And if you have a chance (and you think the plugin earned it) please don’t forget to 5 start reviewing it =)


    Regards!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to set a dropdown option’ is closed to new replies.