jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 在提交之前收听Semantic UI表单验证错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用语义UI表单,模态和验证,我有一个模态的表单,如果表单无效(在提交时发生),我不希望模式关闭. @H_403_7@

@H_403_7@我可以阻止模态关闭的唯一方法是在提交按钮中添加一个禁用的类.

@H_403_7@我希望听取表格(实时)并根据当前表单验证状态打开和关闭禁用的类.

@H_403_7@我只能在提交表单后才能使其工作,但不是实时的

@H_403_7@

$('#myForm')
    .form({
        title: {
            identifier  : 'title',rules: [
                {
                    type   : 'empty',prompt : 'Please enter a title'
                },{
                    type   : 'length[2]',prompt : 'at least 6 characters'
                }
            ]
        }
    },{
        onsuccess: function() {
            $('#submit').removeClass('disabled');
        },onFailure: function() {
            $('#submit').addClass('disabled');
        }
    }
);

解决方法

而不是使用禁用提交,确保模式保持打开,即使单击提交(模态批准)按钮,并将决定关闭模式传递到语义UI表单验证事件(即onsuccess). @H_403_7@

@H_403_7@所以类似的东西:

@H_403_7@

$('.ui.modal').modal({
        onApprove : function() {
          //Submits the semantic ui form
          //And pass the handling responsibilities to the form handlers,// e.g. on form validation success
          $('.ui.form').submit();
          //Return false as to not close modal dialog
          return false;
        }
    });

var formValidationRules =
{
    title: {
        identifier  : 'title',rules: [
            {
                type   : 'empty',prompt : 'Please enter a title'
            },{
                type   : 'length[2]',prompt : 'at least 6 characters'
            }
        ]
    }
}

var formSetTings =
{
    onsuccess : function() 
    {
      //Hides modal on validation success
      alert("Valid Submission,modal will close.");
      $('.modal').modal('hide');
    }
}

$('.ui.form').form(formValidationRules,formSetTings);
@H_403_7@请注意,“OnApprove”事件仅在您单击“ok”类的模式按钮时触发.
所以你需要一个模态按钮,如下所示:

@H_403_7@

<div class="ui ok green basic inverted button">
  <i class="checkmark icon"></i>
  Submit
</div>
@H_403_7@这是我创建的扩展工作plunker代码,用于演示:
http://plnkr.co/edit/5fK7UuJIm7QTJGiu23NL?p=preview

大佬总结

以上是大佬教程为你收集整理的jquery – 在提交之前收听Semantic UI表单验证错误全部内容,希望文章能够帮你解决jquery – 在提交之前收听Semantic UI表单验证错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。