gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:13:11 25 4
gpt4 key购买 nike

尝试从理想表单中删除验证规则,但无法摆脱它!。当值小于 3 时,我添加规则来验证 4 个额外字段,但当我输入的值大于 3 时,我希望删除此验证。我一直试图在 else 语句内添加但不起作用。请帮忙

$('#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[]');

最佳答案

$('#employment_details').change(function() {
if (this.value == 'Retired') {
$('form.idealforms').idealforms('toggleFields', 'company_name getemployed');
$('form.idealforms').idealforms('goToStep', 5);
}

if (this.value == 'Employed') {
$('form.idealforms').idealforms('toggleFields', 'monthly_pension_amount pension_type getretired');
$('form.idealforms').idealforms('goToStep', 5);
}

$('#employment_details').attr('disabled', 'disabled');
});

关于javascript - 如何从 Ideal Forms jQuery 中删除验证规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30693997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com