• Resolved jodiplannes

    (@jodiplannes)


    Is it possible to change the selection in a dropdown menue (Select) using javascript.
    Changing values in regular input fields like text and number fields is no problem, but I do not see how to change a selection.

    I have tried editing which selection have the “current” class and simply editing the value shown, but to no avail.

    Is it at all possible?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @jodiplannes,

    The easiest workaround would be to switch the form setting for “Design style” to “None” under the “Appearance” tab so that the default select HTML tag is only used in the form so that you could easily use jQuery to select via the following code:
    jQuery("#select-1-field").val('option-3');

    Where “option-3” would be the value of the select option.

    Other than that by default Forminator uses the custom JQuery and adds ul and li HTML tags to structure the selection dropdown menu for “Design Styles” other than “None”, so it would require more custom changes to make to change the dropdown selection using jQuery.

    I have tried editing which selection have the “current” class and simply editing the value shown, but to no avail.

    The above-shared jQuery code would be the one which gets submitted, so you could implement that along with your existing jQuery code to see whether that helps.

    Please do check and advise if I’m missing anything. Have a nice day ahead.

    Kind Regards,
    Nithin

    Thread Starter jodiplannes

    (@jodiplannes)

    Hi, Thank you for the reply!

    A actually just figured out a workaround using regular Javascript. I updated the “select-value” and used element.setAttribute("aria-invalid" , "false"); which kind of did the trick.

    selectField = document.getElementById('select-3-field');
    selectField.value = "some-value"
    selectField.setAttribute("aria-invalid" , "false");

    Editing the visual part turned out to be more difficult however. After a lot of trial and error I figured out my problem; the “forminator-value” div was not loaded in immediately. So to address this i set a timeout before getting these elements.

    selectField = document.getElementById('select-3-field');

    setTimeout(function(){displayValue= selectField.nextSibling.getElementsByClassName('forminator-value')[0];
                                allValues= Array.from(selectField.nextSibling.getElementsByClassName('forminator-dropdown-list')[0].childNodes);,500);

    I have wasted more time on this than I would like to admit, but hopefully this could help someone in the future.

    • This reply was modified 4 years, 5 months ago by jodiplannes.
    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hello @jodiplannes,

    I’m glad you were able to find a way and resolve things on your end. Also, thank you for pointing out how you resolved it as that can surely be helpful to someone. Should you have any doubts or need any help, feel free reply here or open a fresh thread and we would be happy to help.

    Thank you,
    Prathamesh Palve

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Prefill dropdown menues (Select)’ is closed to new replies.