EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: crosemffet on November 27, 2015, 02:55:32 PM



Title: validate textbox only if another textbox validates
Post by: crosemffet on November 27, 2015, 02:55:32 PM
hello again everybody. I don't want to abuse, but I'm facing a new problem in my form validation process.
I have 2 fields, field#1 and field#2. field#2 must validate as required and length[2,10], but ONLY if field#1 has data and is valid.
the idea is: user has one second field that needs to be validated only if first field was completed and meets the validation.
I've been trying with the extend equals function provided in email example without success.
any help will be appreciated,
thanks again for your support ! ! !.


Title: Re: validate textbox only if another textbox validates
Post by: stworthy on November 28, 2015, 03:10:05 AM
You can set the 'novalidate' property to true for the field2 to disable the validation. When the field1 is validated, call 'enableValidation' method on the field2 to enable it. Please refer to the code below:
Code:
$('#field1').validatebox({
required:true,
validType:'length[2,10]',
onValidate: function(valid){
if ($(this).val() && valid){
$('#field2').validatebox('enableValidation');
}
}
});
$('#field2').validatebox({
required:true,
validType:'length[2,10]',
novalidate:true
})