After some days off miserable testing and trying to figure out what I'm doing wrong I decided to ask it here.
I'm trying to write a custom validation rule that validates the combination of 2 fields (first & last name). The rule itself is very straight forward, it's a max-length.
I've created this rule and added it to the form field, now I'm unable to get it working. There is just no response, no error messages to be found (no in console or the logs). I started out with a separate js file for the custom rules/ custom js and added it to the page.xml. Meanwhile I've tried adding it to the validation.js to be sure the rule get's loaded, same result.
I have the following questions:
- If validating 2 fields, does the rule needs to be set on both (the css-class)
- How would I debug validation rules
This is what I've tried:
Validation.addAllThese([
['validate-name-length', 'The combination of first & last name cannot exceed 30 characters.<br/>Use initials if needed', function(v) {
var length_firstname = $('billing[firstname]').value.length;
var length_lastname = $('billing[lastname]').value.length;
var result = true;
if ((length_firstname + length_lastname) > 30) {
result = false;
} else {
result = true;
}
return result;
}]
}];
I've tried to work with the passed field in the validation but then you have difficulties getting the other field's value.
I have a strong feeling I made some stupid mistake and I'm looking over it. I get confused really quick with the Prototype/JQuery use in Magento. Any help would be appreciated.