I'm following this example, http://livevalidation.com/documentation#ValidateCustom , to check if both fields are filled in. So if the first field is not blank the second one cannot be blank and vice versa.
Can anyone figure out why this code isn't working?
var txtFirstName = new LiveValidation('txtTaco', {onlyOnSubmit: true } );
txtFirstName.add(
Validate.Custom( 1, { against: function(value,args){
if(args.first||args.last){
if(args.first&&args.last){
return true;
} else {
return false;
}
}
},
args: {
first:txtTaco.value,
last:lastName.value}
}) //end custom
); // end add
There were several issues with your question and fiddle:
<form>, soonlyOnSubmitwill never trigger<input>tags aren't closedif (condition) { return true } else { return false }, justreturn (condition)txtTacoWorking with the solution i found some issues with livevalidation:
displayMessageWhenEmptyto validate when the field is emptyvalidMessage. According to comments on the source code, you need to set it to false to hide it, but this don't work. So I just set it to a space.I did only one validator, for last name. When you change the first name it calls the last name validator. The downside is that if you style the border color of the invalid field, only last name will change.
Here's the final code:
And fiddle: http://jsfiddle.net/P7Cf3/