Skip to content

Commit 48ed7ff

Browse files
author
Tom Hanoldt
committed
dist v1.0.2
1 parent 6e2232b commit 48ed7ff

File tree

6 files changed

+35
-29
lines changed

6 files changed

+35
-29
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ It also exposes the class `InputValidator` for manual instantiating.
168168
[Tom Hanoldt](https://www.tomhanoldt.info)
169169

170170
## Changelog
171+
### 1.0.2
172+
* fix error hint
173+
* change rule ordering
174+
171175
### 1.0.1
172176
* readme
173177

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery.input.validator",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"homepage": "https://github.com/creative-workflow/jquery.input.validator",
55
"authors": [
66
"Tom Hanoldt <tom@creative-workflow.berlin>"

dist/jquery.input.validator.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,6 @@
2525
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])?)*$/
2626
},
2727
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-
},
4628
minlength: function(validator, $element, value) {
4729
if (!$element.attr('minlength')) {
4830
return true;
@@ -68,6 +50,24 @@
6850
}
6951
return !!value;
7052
},
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+
},
7171
pattern: function(validator, $element, value) {
7272
if (!$element.attr('pattern') || !('' + value).length) {
7373
return true;
@@ -104,12 +104,13 @@
104104
onBuildErrorElement: function(validator, $element, value, errors) {
105105
var $hint, error;
106106
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;
110111
}
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);
113114
},
114115
onValidIntern: function(validator, $element, value, errors) {
115116
var classes;
@@ -131,6 +132,7 @@
131132
classes = validator.config.classes;
132133
$element.removeClass(classes.error + " " + classes.valid);
133134
$($element.data('inputvalidator-hint')).remove();
135+
$element.data('inputvalidator-hint', void 0);
134136
if (typeof (base = validator.config.handler).onReset === "function") {
135137
base.onReset(validator, $element);
136138
}
@@ -242,13 +244,13 @@
242244
}
243245
}
244246
if (errors.length > 0) {
245-
$element.attr('invalid', true);
247+
$element.data('invalid', true);
246248
this.config.handler.onInvalidIntern(this, $element, value, errors);
247249
if (this.config.focusInvalidElement) {
248250
$element.first().focus();
249251
}
250252
} else {
251-
$element.attr('invalid', false);
253+
$element.data('invalid', false);
252254
this.config.handler.onValidIntern(this, $element, value, errors);
253255
}
254256
return errors;

dist/jquery.input.validator.js.gz

-48 Bytes
Binary file not shown.

dist/jquery.input.validator.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery.input.validator",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "This module helps to handle input validation based on standard html attributes.",
55
"main": "dist/jquery.input.validator.js",
66
"repository": {

0 commit comments

Comments
 (0)