Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter mihaibalan

    (@mihaibalan)

    Hi everyone! I’ve figured it out by myself! Let me explain how I’ve done it: I’m not a professional developer so please excuse me if my language isn’t professional but I’ll do my best to explain it clearly. Maybe it will help somebody else!

    So Forminators conditional logic works based on javascript eventlisteners that are waiting for a “change” event to call their linked function.
    Filling the forms with a javascript form does not count as an event, so the conditional logic never fires even if the form is filled.

    I’ve written this bit of code to fix it:

    //define variables
    const e = new Event(“change”)
    var select = document.getElementsByClassName(“forminator-select–field forminator-select2”);

    // define dispatchevent function
    function fixselect(f){
    f.dispatchEvent(e)
    }
    //for loop through all selects
    for (var i = 0; i < select.length; i++) {
    fixselect(select[i]);
    }

    Technically what happens is that all of the select fields have this class name:
    “forminator-select–field forminator-select2”
    So I define a variable that selects all of the select fields, the problem is that this creates a HTML list, that is why we have to use a for loop in order to dispatch individual events on each selected element, doing so on document, window or the HTML list does not work.

    The one in the middle just creates the dispatchEvent() function that is called in the for loop,which triggers a change event (the “e” variable) manually.

    Hope this will help someone, I’m super happy with how it worked out.

Viewing 1 replies (of 1 total)