EasyUI Forum
May 24, 2024, 09:56:32 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: validate textbox only if another textbox validates  (Read 4827 times)
crosemffet
Jr. Member
**
Posts: 68



View Profile WWW Email
« 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 ! ! !.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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
})
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!