jQuery Validate插件 - 按下特定按钮时运行

时间:2015-06-01 14:47:45

标签: jquery jquery-validate

我正在使用http://jqueryvalidation.org/,并且工作正常

<button type="submit" name="submit" value="complete" class="btn green"><i class="fa fa-check"></i> Complete Section</button>
<button type="submit" name="submit" value="save" class="btn green"><i class="fa fa-save"></i> Save</button>

var form1 = $('#form_sample_1');
var error1 = $('.alert-danger', form1);
var success1 = $('.alert-success', form1);

form1.validate({
  errorElement: 'span', //default input error message container
  errorClass: 'help-block help-block-error', // default input error message class
  focusInvalid: false, // do not focus the last invalid input
  ignore: "",  // validate all fields including form hidden input
  invalidHandler: function (event, validator) { //display error alert on form submit              
                    success1.hide();
                    error1.show();
                    Metronic.scrollTo(error1, -200);
                },

   highlight: function (element) { // hightlight error inputs
   $(element)
   .closest('.form-group').addClass('has-error'); // set error class to the control group
                },

                unhighlight: function (element) { // revert the change done by hightlight
                    $(element)
                        .closest('.form-group').removeClass('has-error'); // set error class to the control group
                },

                success: function (label) {
                    label
                        .closest('.form-group').removeClass('has-error'); // set success class to the control group
                },

                submitHandler: function (form) {
                    form.submit();
                }
            });

然而,我理想的是,如果按下“保存”按钮,表单将被提交并且未经过验证,即仅在按下“完成”按钮时进行验证。

0 个答案:

没有答案