jQuery.validationEngine v2.6.1仅有时验证? [英] jQuery.validationEngine v2.6.1 Only Validates Sometimes?

查看:155
本文介绍了jQuery.validationEngine v2.6.1仅有时验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码看起来像是连接起来的(像这样)。

$ p $ jQuery(#contactForm)。validationEngine();

,因为它会在下列情况下验证并产生错误信息:




  • 您在没有任何输入的情况下从必填字段中跳出

  • 至少需要输入一个字符到需要更多字段的字段,然后单击提交按钮



但是如果除了点击提交按钮之外什么都不做,它将不会验证并产生错误信息。在这种情况下,它只是提交。一旦你点击该领域或输入任何东西,它似乎工作。



我有什么可以查找我错误配置?



HTML:

 < form class =contactformid =contactForm > 
< fieldset>
< div class =contactform-name contactform-field>
< label class =contactform-labelfor =contactform-name>名称:
< br>
< / label>
< input class =validate [required,minSize [8]] contactform-inputtype =textid =contactform-namename =name/>
< / div>

< div class =contactform-email contactform-field>
< label class =contactform-labelfor =contactform-email>电子邮件地址:< br>< / label>
< input value class =validate [required,custom [email]] contactform-inputtype =emailid =contactform-emailname =contactform-email/>
< / div>

< div class =contactform-text contactform-field>
< label class =contactform-labelfor =contactform-text>消息:
< br>
< / label>
< textarea class =validate [required,minSize [12]] contactform-inputname =textid =contactform-text> < / textarea的>
< / div>

< input class =contactform-b​​uttontype =submitname =submitvalue =Send/>

< / fieldset>
< / form>

JavaScript(它在Meteor中运行):

  Template.Contact.rendered = function(){
jQuery(#contactForm)。validationEngine();
}


解决方案

引擎,但从文档我发现'附加'将附加验证器form.submit。它可以这么简单吗?



https://github.com/posabsolute/jQuery-Validation-Engine#attach



编辑:



你也可以对提交事件做些什么(如果上面的提示不起作用)。

类似于这(未测试,但应该把你放在正确的路径):

  Template.templateName.events({
'submit':function(event){

//防止使用preventDefault()提交
event.preventDefault();

//做一些检查提交等


});


The code appears to be hooked up (like this)

jQuery("#contactForm").validationEngine();

because it will validate and raise an error bubble if:

  • you tab out of required field without any input
  • you type at least one character into a field that requires more and then click the submit button

But it will not validate and raise an error bubble if you do nothing at all except click the submit button. In that case, it just submits. Once you click in the field or enter anything at all, it seems to work.

What can I be looking for that I've mis-configured?

The HTML:

<form class = "contactform" id = "contactForm">
    <fieldset>
        <div class="contactform-name contactform-field">
            <label class="contactform-label" for="contactform-name">Name:
                <br>
            </label>
            <input class="validate[required,minSize[8]] contactform-input" type="text" id="contactform-name" name="name" />
        </div>

        <div class="contactform-email contactform-field">
            <label class="contactform-label" for="contactform-email">Email Address:<br></label>
            <input value class="validate[required,custom[email]] contactform-input" type="email" id="contactform-email" name="contactform-email" />
        </div>

        <div class="contactform-text contactform-field">
            <label class="contactform-label" for="contactform-text">Message:
                <br>
            </label>
            <textarea class="validate[required,minSize[12]]contactform-input" name="text" id="contactform-text" > </textarea>
        </div>

        <input class="contactform-button" type="submit" name="submit" value="Send" />

    </fieldset>
</form>

The JavaScript (it's running in Meteor):

Template.Contact.rendered = function () {
    jQuery("#contactForm").validationEngine();
}

解决方案

I've never used this engine, but from the docs I found that 'attach' will attach the validator to form.submit. Can it be as simple as that?

https://github.com/posabsolute/jQuery-Validation-Engine#attach

EDIT:

You can also do stuff to the submit-event (if the tip above won't help).

Something like this (not tested, but should put you in the correct path):

Template.templateName.events({
   'submit': function(event) {

      // Prevent the submit with preventDefault()
      event.preventDefault();

      // Do something to check the submit etc.

   }
});

这篇关于jQuery.validationEngine v2.6.1仅有时验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆