I have seen the clear FAQ on how to dynamically update the options in a dropdown using a call to a standalone page with a PHP action that return the options, but in a CF7 port I wanted to stick with updating the options within javascript code to avoid a major rewrite.
I have found I can do this using Nui.Dropdown.getInstance(field).updateOptions(options) which is working nicely. Here is some dumbed down JS code illustrating this:
myDropdownField = document.getElementById('myDropdownID');
myOptions = new Array();
myOptions[""] = "Select course...";
for (let i = 1 ; i<=3; i++)
{
myOptions["opt-"+i] = "My option text "+i;
}
Nui.Dropdown.getInstance(myDropdownField).updateOptions(myOptions);
I wanted to check if its ok (ie future version proof etc) to use this function from custom JS or if we should stick to the approach demonstrated in the FAQ?
You need to login to be able to post a reply.
