|
101 | 101 | onValid: null, |
102 | 102 | onInvalid: null, |
103 | 103 | onReset: null, |
104 | | - onBuildErrorElement: function(validator, $element, value, errors) { |
| 104 | + onBuildErrorHint: function(validator, $element, value, errors) { |
| 105 | + return $(("<label class='" + validator.config.classes.hint + "' ") + ("for='" + ($element.attr('id')) + "'></label>")); |
| 106 | + }, |
| 107 | + onBuildErrorHintIntern: function(validator, $element, value, errors) { |
105 | 108 | var $hint, error; |
106 | 109 | error = errors[0]; |
107 | 110 | $hint = $element.data('inputvalidator-hint'); |
108 | | - if ($hint) { |
109 | | - $hint.html(error.message); |
110 | | - return; |
| 111 | + if (!$hint) { |
| 112 | + $hint = validator.config.handler.onBuildErrorHint(validator, $element, value, errors); |
| 113 | + $element.data('inputvalidator-hint', $hint).after($hint); |
111 | 114 | } |
112 | | - $hint = $(("<label class='" + validator.config.classes.hint + "' ") + ("for='" + ($element.attr('id')) + "'>") + error.message + "</label>"); |
113 | | - return $element.data('inputvalidator-hint', $hint).after($hint); |
| 115 | + return $hint.html(error.message); |
114 | 116 | }, |
115 | 117 | onValidIntern: function(validator, $element, value, errors) { |
116 | 118 | var classes; |
|
119 | 121 | return $element.removeClass(classes.error).addClass(classes.valid); |
120 | 122 | }, |
121 | 123 | onInvalidIntern: function(validator, $element, value, errors) { |
122 | | - var base, base1, classes; |
| 124 | + var base, classes; |
123 | 125 | classes = validator.config.classes; |
124 | 126 | $element.removeClass(classes.valid).addClass(classes.error); |
125 | | - if (typeof (base = validator.config.handler).onBuildErrorElement === "function") { |
126 | | - base.onBuildErrorElement(validator, $element, value, errors); |
127 | | - } |
128 | | - return typeof (base1 = validator.config.handler).onInvalid === "function" ? base1.onInvalid(validator, $element, value, errors) : void 0; |
| 127 | + validator.config.handler.onBuildErrorHintIntern(validator, $element, value, errors); |
| 128 | + return typeof (base = validator.config.handler).onInvalid === "function" ? base.onInvalid(validator, $element, value, errors) : void 0; |
129 | 129 | }, |
130 | 130 | onResetIntern: function(validator, $element) { |
131 | 131 | var base, base1, classes; |
|
146 | 146 | if (config == null) { |
147 | 147 | config = {}; |
148 | 148 | } |
149 | | - this.getMessage = bind(this.getMessage, this); |
| 149 | + this.messageFor = bind(this.messageFor, this); |
150 | 150 | this.elements = bind(this.elements, this); |
151 | 151 | this.resetElement = bind(this.resetElement, this); |
152 | 152 | this.reset = bind(this.reset, this); |
|
204 | 204 | if (this.config.validateOnClick) { |
205 | 205 | return $elements.click((function(_this) { |
206 | 206 | return function(e) { |
207 | | - var errors; |
208 | | - return errors = _this.validateElement(e.target); |
| 207 | + return _this.validateElement(e.target); |
209 | 208 | }; |
210 | 209 | })(this)); |
211 | 210 | } |
|
236 | 235 | rule = ref[name]; |
237 | 236 | if (!rule(this, $element, value)) { |
238 | 237 | errors.push({ |
239 | | - message: $element.data("msg-" + name) || this.getMessage(name), |
| 238 | + message: $element.data("msg-" + name) || this.messageFor(name), |
240 | 239 | element: $element, |
241 | 240 | rule: name, |
242 | 241 | value: value |
|
277 | 276 | return $(this.config.selectors.elements, context).not(this.config.selectors.ignore); |
278 | 277 | }; |
279 | 278 |
|
280 | | - InputValidator.prototype.getMessage = function(name) { |
| 279 | + InputValidator.prototype.messageFor = function(name) { |
281 | 280 | var ref; |
282 | 281 | if (!((ref = this.config.messages) != null ? ref[name] : void 0)) { |
283 | 282 | return this.config.messages.generic; |
|
0 commit comments