|
25 | 25 | email: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ |
26 | 26 | }, |
27 | 27 | rules: { |
28 | | - number: function(validator, $element, value) { |
29 | | - if ($element.attr('type') !== 'number' || !('' + value).length) { |
30 | | - return true; |
31 | | - } |
32 | | - return validator.config.pattern.number.test(value); |
33 | | - }, |
34 | | - tel: function(validator, $element, value) { |
35 | | - if ($element.attr('type') !== 'tel' || !('' + value).length) { |
36 | | - return true; |
37 | | - } |
38 | | - return validator.config.pattern.tel.test(value); |
39 | | - }, |
40 | | - email: function(validator, $element, value) { |
41 | | - if ($element.attr('type') !== 'email' || !('' + value).length) { |
42 | | - return true; |
43 | | - } |
44 | | - return validator.config.pattern.email.test(value); |
45 | | - }, |
46 | 28 | minlength: function(validator, $element, value) { |
47 | 29 | if (!$element.attr('minlength')) { |
48 | 30 | return true; |
|
68 | 50 | } |
69 | 51 | return !!value; |
70 | 52 | }, |
| 53 | + number: function(validator, $element, value) { |
| 54 | + if ($element.attr('type') !== 'number' || !('' + value).length) { |
| 55 | + return true; |
| 56 | + } |
| 57 | + return validator.config.pattern.number.test(value); |
| 58 | + }, |
| 59 | + tel: function(validator, $element, value) { |
| 60 | + if ($element.attr('type') !== 'tel' || !('' + value).length) { |
| 61 | + return true; |
| 62 | + } |
| 63 | + return validator.config.pattern.tel.test(value); |
| 64 | + }, |
| 65 | + email: function(validator, $element, value) { |
| 66 | + if ($element.attr('type') !== 'email' || !('' + value).length) { |
| 67 | + return true; |
| 68 | + } |
| 69 | + return validator.config.pattern.email.test(value); |
| 70 | + }, |
71 | 71 | pattern: function(validator, $element, value) { |
72 | 72 | if (!$element.attr('pattern') || !('' + value).length) { |
73 | 73 | return true; |
|
104 | 104 | onBuildErrorElement: function(validator, $element, value, errors) { |
105 | 105 | var $hint, error; |
106 | 106 | error = errors[0]; |
107 | | - $hint = $element.parent().find(validator.config.classes.hint); |
108 | | - if (!$hint.length) { |
109 | | - $hint = $(("<label class='" + validator.config.classes.hint + "' ") + ("for='" + ($element.attr('id')) + "'>") + error.message + "</label>"); |
| 107 | + $hint = $element.data('inputvalidator-hint'); |
| 108 | + if ($hint) { |
| 109 | + $hint.html(error.message); |
| 110 | + return; |
110 | 111 | } |
111 | | - $element.data('inputvalidator-hint', $hint); |
112 | | - return $element.after($hint); |
| 112 | + $hint = $(("<label class='" + validator.config.classes.hint + "' ") + ("for='" + ($element.attr('id')) + "'>") + error.message + "</label>"); |
| 113 | + return $element.data('inputvalidator-hint', $hint).after($hint); |
113 | 114 | }, |
114 | 115 | onValidIntern: function(validator, $element, value, errors) { |
115 | 116 | var classes; |
|
131 | 132 | classes = validator.config.classes; |
132 | 133 | $element.removeClass(classes.error + " " + classes.valid); |
133 | 134 | $($element.data('inputvalidator-hint')).remove(); |
| 135 | + $element.data('inputvalidator-hint', void 0); |
134 | 136 | if (typeof (base = validator.config.handler).onReset === "function") { |
135 | 137 | base.onReset(validator, $element); |
136 | 138 | } |
|
242 | 244 | } |
243 | 245 | } |
244 | 246 | if (errors.length > 0) { |
245 | | - $element.attr('invalid', true); |
| 247 | + $element.data('invalid', true); |
246 | 248 | this.config.handler.onInvalidIntern(this, $element, value, errors); |
247 | 249 | if (this.config.focusInvalidElement) { |
248 | 250 | $element.first().focus(); |
249 | 251 | } |
250 | 252 | } else { |
251 | | - $element.attr('invalid', false); |
| 253 | + $element.data('invalid', false); |
252 | 254 | this.config.handler.onValidIntern(this, $element, value, errors); |
253 | 255 | } |
254 | 256 | return errors; |
|
0 commit comments