Is there a bug with min=“0” in jquery validation? Or am I overlooking something?

倖福魔咒の 提交于 2019-12-23 19:14:17

问题


jQuery validation seems to work fine with min="1" and min="-1", but not with min="0". Consider this jsFiddle. It appropriately objects to a value of -5 in the first input element and in the third, but accepts a -5 in the second one, where min="0".

Is this a bug in jQuery validation or am I overlooking something?

<form id="myform">
  <input type="text" name="negativeone" min="-1"/>
  <br/>
  <input type="text" name="zero" min="0"/>    
  <br/>
<input type="text" name="one" min="1" />
</form> 
<button id="event2">Test</button>
<a href="http://docs.jquery.com/Plugins/Validation" target="_blank">Validation Documentation</a>

JavaScript

$(document).ready(function () {
    $('#myform').validate({
    });

    $('#event2').on('click', function () {
        $('#myform').valid();
    });
});

回答1:


To answer your question:

"No", you're not overlooking anything, and "Yes", this appears to be a bug.

Look at these two identical jsFiddles, where only the version is different...

jQuery Validate v1.10 (no bug): http://jsfiddle.net/mblase75/MgvRn/

jQuery Validate v1.11.1 (bug): http://jsfiddle.net/MgvRn/1/

Also, this only appears to be an issue when using HTML5 validation attributes.

Until the plugin is fixed, a workaround would be to just declare the rule inside .validate().

$('#myform').validate({
    rules: {
        zero: {
            min: 0
        }
    }
});

Working DEMO (v1.11.1): http://jsfiddle.net/MgvRn/2/


I suggest that you report this bug on the developer's Github page:

https://github.com/jzaefferer/jquery-validation/



来源:https://stackoverflow.com/questions/18255741/is-there-a-bug-with-min-0-in-jquery-validation-or-am-i-overlooking-something

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!