如何从Ideal Forms jQuery中删除验证规则

时间:2015-06-07 13:19:09

标签: javascript jquery validation rules idealforms

尝试从Ideal Forms中删除验证规则,但无法摆脱它! 当值小于3时,我正在添加规则以验证4个额外字段,但是当我输入的值超过3时,我希望删除此验证。我一直在尝试添加其他语句,但不起作用。请帮忙

$('#previous_year').keyup("input", function() {
        var dInput = this.value;

        if(parseInt(dInput) < 3){
           $('form.idealforms').idealforms('addRules', {
            'postcode4': (parseInt(dInput) < 3) ? 'required' : '',
            'memo3': (parseInt(dInput) < 3) ? 'required' : '',
            'previous_year2': (parseInt(dInput) < 3) ? 'required' : '',
            'previous_month2': (parseInt(dInput) < 3) ? 'required' : ''
                    });
                    $('form.idealforms').idealforms('goToStep', 3);
            } else {

//remove rule here!

            } 
});

看了一下文档,我得到了以下更新,但这仍然是错误的,就好像你有下拉并选择一个选项,你正在禁用元素,如果你选择其他选项,你正在启用它,它是一个直接循环

.idealforms('toggleFields', names)

Show or hide fields. When the fields are hidden they will be excluded from the validation.

names: A space separated string of name attributes.
Example:

$('form').idealforms('toggleFields', 'username password hobbies[]');

1 个答案:

答案 0 :(得分:1)

<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <meta charset="utf-8">
    </head>
    <body>
        <div id="myDiv"></div>

        <!-- Script at the end -->
        <script type="text/javascript" >
            var url = "script.php?url=http://www.scientificamerican.com";

            var xhr = new XMLHttpRequest();
            xhr.open('GET', url, true );
            xhr.onreadystatechange = function() {
                // Do ur stuff here
                if (xhr.readyState==4 && xhr.status==200) {
                    document.getElementById("myDiv").innerHTML = xhr.responseText;
                }
            }
            xhr.send(null);
        </script>
    </body>
</html>