Skip to content
Browse files

Added patch for tabbing

  • Loading branch information...
1 parent 02ad0cf commit 678bb98d4cde9add6acc56b081d69f9c9ef10bbc Nathan Smith committed Jun 18, 2009
Showing with 15 additions and 2 deletions.
  1. +15 −2 validation.js
View
17 validation.js
@@ -86,7 +86,20 @@ Validation.prototype = {
var useTitles = this.options.useTitles;
var callback = this.options.onElementValidate;
Form.getElements(this.form).each(function(input) { // Thanks Mike!
+
Event.observe(input, 'blur', function(ev) { Validation.validate(Event.element(ev),{useTitle : useTitles, onElementValidate : callback}); });
+ Event.observe(input, 'keyup', function(ev) {
+ var KEY_SHIFT_TAB = 16,
+ isTab = ev.keyCode === Event.KEY_TAB ||
+ ev.keyCode === KEY_SHIFT_TAB;
+
+ // Do not validate if just tabbed to and empty
+ if (isTab && $F(input).empty()) { return; }
+
+ Validation.validate(Event.element(ev),{useTitle : useTitles, onElementValidate : callback});
+ });
+ Event.observe(input, 'change', function(ev) { Validation.validate(Event.element(ev),{useTitle : useTitles, onElementValidate : callback}); });
+
});
}
},
@@ -136,7 +149,7 @@ Object.extend(Validation, {
var advice = Validation.getAdvice(name, elm);
if(advice == null) {
var errorMsg = useTitle ? ((elm && elm.title) ? elm.title : v.error) : v.error;
- advice = '<div class="validation-advice" id="advice-' + name + '-' + Validation.getElmID(elm) +'" style="display:none">' + errorMsg + '</div>'
+ advice = '<span class="error" id="advice-' + name + '-' + Validation.getElmID(elm) +'" style="display:none">' + errorMsg + '</span>'
switch (elm.type.toLowerCase()) {
case 'checkbox':
case 'radio':
@@ -277,4 +290,4 @@ Validation.addAllThese([
return $F(elm);
});
}]
-]);
+]);

0 comments on commit 678bb98

Please sign in to comment.
Something went wrong with that request. Please try again.