Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed issue where custom validation rules were not firing #21

Closed
wants to merge 1 commit into from

2 participants

@pusherman

Code was checking for the method name to have a prefix of callback_ which the methods did not. Took out that check, seems to be working as expected now.

@rickharrison
Owner

That is actually incorrect. This code checks to see if a rule has the prefix of callback_ which is required in the rule definition. A custom rule works in that you name it "callback_name_here" in the rules array and then register it like so:

validator.registerCallback('name_here', function() {
    return false;
});

This was designed to work the exact same as code igniter. If you think that this syntax is confusing, I am open to suggestions on a better option.

@pusherman

Ahh, I see. I must have missed the part in your documentation where it says you name the rule with a callback_ prefix.

But yeah, this is kind of confusing to me. Why not just have the name match the function that's actually being called?

@rickharrison
Owner

I assume code igniter chose to do it this way to avoid any possible collisions with other system rules. I may change this so that callback_ is not required as I am not necessarily tied to the ci implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 31, 2012
  1. @pusherman
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 8 deletions.
  1. +4 −8 validate.js
View
12 validate.js
@@ -219,19 +219,15 @@
/*
* If the hook is defined, run it to find any validation errors
*/
-
if (typeof this._hooks[method] === 'function') {
if (!this._hooks[method].apply(this, [field, param])) {
failed = true;
}
- } else if (method.substring(0, 9) === 'callback_') {
- // Custom method. Execute the handler if it was registered
- method = method.substring(9, method.length);
- if (typeof this.handlers[method] === 'function') {
- if (this.handlers[method].apply(this, [field.value]) === false) {
- failed = true;
- }
+ // Custom method. Execute the handler if it was registered
+ } else if (typeof this.handlers[method] === 'function') {
+ if (this.handlers[method].apply(this, [field.value]) === false) {
+ failed = true;
}
}
Something went wrong with that request. Please try again.