Skip to content

Commit 0a7c69d

Browse files
committed
Remove a curly brace and update README
1 parent f4b7802 commit 0a7c69d

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# html5-form-validator
1+
# HTML5 Form Validator
2+
23
The most simple HTML5 forms validator
4+
5+
## Install
6+
7+
```
8+
npm i html5-form-validator
9+
```
10+
11+
or
12+
13+
```
14+
yarn add html5-form-validator
15+
```
16+
17+
## Usage
18+
19+
```
20+
import 'html5-form-validator';
21+
```
22+
23+
Then initialize with default settings:
24+
25+
```
26+
new html5formValidation();
27+
```
28+
29+
or supply your own
30+
31+
```
32+
const form = document.querySelector('#form');
33+
34+
new html5formValidation(form, {
35+
errorElement: 'form__error',
36+
invalidClass: 'is--invalid',
37+
submitHandler(instance) {
38+
console.log(instance)
39+
},
40+
validateOnInput: false
41+
});
42+
```
43+
44+
## Options
45+
46+
`errorElement` - The classname of the element that will be added to the dom after the required field. Defaults to `error`.
47+
48+
`invalidClass` - The classname of the required field when it is invalid. Defaults to `invalid`.
49+
50+
`submitHandler` - A function to run on valid form submission. Accepts a single `instance` argument which refers to the constuctor's instance. Defaults to `null`.
51+
52+
`validateOnInput` - Set to false if you want to show visual feedback for invalid fields after the first invalid submission. Defaults to `true`.

demo/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
} else {
4646
if (typeof this.settings.submitHandler === 'function') {
4747
event.preventDefault();
48-
48+
4949
this.settings.submitHandler(this);
5050
}
5151
}
@@ -66,13 +66,13 @@
6666
field.oninvalid = () => {
6767
field.classList.add(this.settings.invalidClass);
6868
field.nextSibling.textContent = field.validationMessage;
69-
}
69+
};
7070

7171
field.oninput = () => {
7272
field.nextSibling.textContent = '';
7373
field.classList.remove(this.settings.invalidClass);
7474
field.checkValidity();
75-
}
75+
};
7676
}
7777
}
7878
</script>

index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class html5formValidation {
2828
} else {
2929
if (typeof this.settings.submitHandler === 'function') {
3030
event.preventDefault();
31-
31+
3232
this.settings.submitHandler(this);
3333
}
3434
}
@@ -49,13 +49,12 @@ export default class html5formValidation {
4949
field.oninvalid = () => {
5050
field.classList.add(this.settings.invalidClass);
5151
field.nextSibling.textContent = field.validationMessage;
52-
}
52+
};
5353

5454
field.oninput = () => {
5555
field.nextSibling.textContent = '';
5656
field.classList.remove(this.settings.invalidClass);
5757
field.checkValidity();
58-
}
58+
};
5959
}
6060
}
61-
}

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "html5-form-validator",
3+
"version": "0.0.1",
4+
"description": "The most simple HTML5 form validator",
5+
"main": "index.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/scriptex/html5-form-validator.git"
9+
},
10+
"keywords": ["HTML5", "form", "validator"],
11+
"author": "Atanas Atanasov <[email protected]> (https://github.com/scriptex)",
12+
"license": "MIT",
13+
"bugs": {
14+
"url": "https://github.com/scriptex/html5-form-validator/issues"
15+
},
16+
"homepage": "https://github.com/scriptex/html5-form-validator#readme"
17+
}

0 commit comments

Comments
 (0)