I am trying to validate two fields using LiveValidation but I can't seem to find anything on it anywhere.
I am trying to make one or the other of the Email and Mobile fields required so that when one is filled in the other does not need to be, but both may be entered.
Here is my code:
<script type="text/javascript">
var Email = new LiveValidation("Email", {validMessage: "", onlyOnBlur: true});
Email.add(Validate.Presence, {failureMessage:"This field is required"});
Email.add(Validate.Format, {pattern: /^[ ]*([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})[ ]*$/i, failureMessage: "A valid email address is required"});
var mobile = new LiveValidation("mobile", {validMessage: "", onlyOnBlur: true});mobile.add(Validate.Presence, {failureMessage:"This field is required"});
var discussion = new LiveValidation("discussion", {validMessage: "", onlyOnBlur: true});discussion.add(Validate.Presence, {failureMessage:"This field is required"});
</script>
I think you can do it, but you'd have to hack it a bit. With the LiveValidation library, there's no function under the LiveValidation class that returns a constant or boolean indicating that a field is validated. However, you can check that the validation message has been added to the DOM. For instance, say I have the code, ->
Now, I want to make sure that f1 is validated. To do this, I would get the parent element of field 'f1', check for elements with the class 'LV_valid', and go from there. My code would look something like, ->
The problem is that there's no way of identifying if the LV field that you retrieved was the one that corresponded with your field. You might have to write your own validation code or make a modified version of the library. That's all the input I can provide right now, hopefully it's valid.