Skip to content Skip to sidebar Skip to footer

JavaScript Toggle Modal Show After Validation

I'm submitting a form through a modal. Based on user input, some data will need sent to the modal. I need to validate the data before loading the modal. The current code prevents s

Solution 1:

@BrentConnor, Per your message in the chat, I'm posting your solution as an answer.

It appears that you had been using the original code I had provided in https://stackoverflow.com/a/27868091/3869056 to stop your modals from opening when a particular action occurs, even if that action inherently is consider a valid trigger. As you pointed out with my answer, it actually broke the ability to open modals.

Rather than returning false for the action, you should stopPropagation() of the parent while targeting the child for testing if it meets the requirements for preventing the launch of the modal.

$('.modal_launcher').click(function(e) {
    // check if any orders are selected
    if($("#order_hold_table_body input:checkbox:checked").length > 0) {
        // append order numbers to the appropriate hold modal
    } else {
        // no orders selected -> alert user & prevent modal.
        e.stopPropagation();
        alert('Choose some orders to put on hold');
    }
}

I'm sorry I couldn't have been a bit more active in helping you to sort it out, but I'm glad my advice led you to the solution. :)


Post a Comment for "JavaScript Toggle Modal Show After Validation"