简体   繁体   English

ASP.NET与Jquery.Validation

[英]ASP.NET vs Jquery.Validation

I am trying to configure valication plugin to perform validation of ASP.NET generated form: 我正在尝试配置验证插件以执行ASP.NET生成形式的验证:

   <script type="text/javascript">
    $(document).ready(function () {

        $("#aspnetForm").validate({
            rules: {
                "<%=ProjectName.ClientID%>": { required: true, minlength: 8 }
            },
            messages: {
                "<%=ProjectName.ClientID%>": { requred: "can not be empty", minlength: "type at least 8 chars" }

            },
            invalidHandler:
             function (form, validator) {
                 alert('validation failed!');
             },
            errorLabelContainer: $("#alert")
        });
    });
</script>

with HTML looking like this: HTML看起来像这样:

 <form name="aspnetForm" method="post" action="CreateProject.aspx"  
 onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ShutUpPostbackButton')" 
 id="aspnetForm" enctype="MULTIPART/FORM-DATA">

 <input id="ctl00_JQueryContent_ProjectName" type="text" style="width:99%;" maxlength="50" name="ctl00$JQueryContent$ProjectName">


 </form>

For some reason the aformenetioned FORM tag has (after loading the page) 出于某种原因,形式化的FORM标签具有(加载页面后)

   novalidate="novalidate" 

inclusion. 包含。 I am clueless where it came from and if it interferes with my validation or not. 我不知道它来自哪里,是否会干扰我的验证。

If I type INVALID one letter in the INPUT, plugin reacts by setting class="valid" to INPUT element, that is, something is working. 如果我在INPUT中输入一个字母INVALID,则插件会通过将class =“ valid”设置为INPUT元素来进行响应,即正在起作用。

Besides getting this to work, I need to know how to disable/enable input elements (mainly buttons) depending on validation outcome. 除了使它起作用之外,我还需要了解如何根据验证结果来禁用/启用输入元素(主要是按钮)。 I know about invalidHandler, but what would be the handler for valid outcome? 我知道invalidHandler,但是有效结果的处理程序是什么? Please note that I need all validation to happen during typing. 请注意,我需要在输入过程中进行所有验证。

This attribute is added by jquery.validate plugin in case of HTML5 validation. 在HTML5验证的情况下,此属性由jquery.validate插件添加。 It is in source (lines 32-33) of jquery.validate: 它在jquery.validate的源代码(第32-33行)中:

// Add novalidate tag if HTML5.
this.attr( "novalidate", "novalidate" );

You can remove this attribute. 您可以删除此属性。 Look on this discussion: http://forum.jquery.com/topic/disable-jquery-validate-when-html5-form-validation-is-present 查看此讨论: http : //forum.jquery.com/topic/disable-jquery-validate-when-html5-form-validation-is-present

submitHandler是什么触发后的成功验证的形式,如你所说, invalidHandler为验证失败的形式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM