试图从理想表格中删除验证规则,但无法摆脱它!当值小于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[]');
$('#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');
});