Skip to content

Commit db6575c

Browse files
author
atanasatanasov
committed
Make sure only one error div is present
1 parent 0a7c69d commit db6575c

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

demo/index.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@
6161
}
6262

6363
validateField(field) {
64-
field.insertAdjacentHTML('afterend', this.errorDiv);
64+
if (
65+
!(
66+
field.nextSibling.classList &&
67+
field.nextSibling.classList.contains(this.settings.errorElement)
68+
)
69+
) {
70+
field.insertAdjacentHTML('afterend', this.errorDiv);
71+
}
6572

6673
field.oninvalid = () => {
6774
field.classList.add(this.settings.invalidClass);
@@ -75,10 +82,11 @@
7582
};
7683
}
7784
}
85+
7886
</script>
7987

8088
<script>
8189
new html5formValidation()
8290
</script>
8391
</body>
84-
</html>
92+
</html>

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,14 @@ export default class html5formValidation {
4444
}
4545

4646
validateField(field) {
47-
field.insertAdjacentHTML('afterend', this.errorDiv);
47+
if (
48+
!(
49+
field.nextSibling.classList &&
50+
field.nextSibling.classList.contains(this.settings.errorElement)
51+
)
52+
) {
53+
field.insertAdjacentHTML('afterend', this.errorDiv);
54+
}
4855

4956
field.oninvalid = () => {
5057
field.classList.add(this.settings.invalidClass);

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "html5-form-validator",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "The most simple HTML5 form validator",
55
"main": "index.js",
66
"repository": {
77
"type": "git",
88
"url": "git+https://github.com/scriptex/html5-form-validator.git"
99
},
1010
"keywords": ["HTML5", "form", "validator"],
11-
"author": "Atanas Atanasov <scriptex.bg@gmail.com> (https://github.com/scriptex)",
11+
"author":
12+
"Atanas Atanasov <scriptex.bg@gmail.com> (https://github.com/scriptex)",
1213
"license": "MIT",
1314
"bugs": {
1415
"url": "https://github.com/scriptex/html5-form-validator/issues"

0 commit comments

Comments
 (0)