jQuery disable button (NOT Submit) until field validates + Validation Plugin

前端 未结 4 1533
孤街浪徒
孤街浪徒 2020-12-02 19:55

I have 4 buttons on my form, a Submit, Cancel, Add and Remove button. All are working as expected but I would like to disable the Add button until the input field validates.

4条回答
  •  一生所求
    2020-12-02 20:15

    jQuery Validate Plugin Documentation: Form Method

    The above method of the validate plugin allows you to check if a form is valid. So if you can't get the callback to work then I would run a timer and check to see if the form is valid every so often, and if so enable your button. This sucks though.

    I can't find a success callback for the validation plug in, so I think you are stuck using the submitHandler method. However, you aren't actually ready to submit the form yet, as you still want to add fields. So my proposed solution is leaving the add button enabled all the time, but having it call a function when clicked to see if the form is valid. If so, then add your field or whatnot, and if not then pop up the errors. So:

    
    ...
    
    ...
    
    

    Or at least something to that effect. Good luck!

提交回复
热议问题