jQuery Validation plugin with two submit buttons?

前端 未结 3 998
天命终不由人
天命终不由人 2020-12-04 22:51

I have one form with around 50 fields and two submit buttons, \"SAVE\" and \"SAVE & SUBMIT\". If the user clicks \"SAVE\", then validate only some values, eg. field1, fi

3条回答
  •  天命终不由人
    2020-12-04 23:24

    If you have the below two buttons:

    You can validate and submit based on the two buttons: Save sends with ajax and no reload. Next button saves and redirects to next page.

    $('form').validate({
                submitHandler: function(form, e) {
                  var button = $(":focus", this);
    
                  var name = button.context.submitButton.defaultValue;
                  console.log(name);
                  if(name == "Save"){
                    $(form).ajaxSubmit();
                  }else{
                    form.submit();
                  }
                }
              });
    

    checkout this post: https://stackoverflow.com/a/61423083/1004799

提交回复
热议问题