initial
This commit is contained in:
commit
74ae93a96e
1 changed files with 94691 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
validation
|
||||
|
||||
- for browser default validation for no custom validation rules use something like this
|
||||
```html
|
||||
<form class="needs-valiation">
|
||||
<input type="text" required>
|
||||
</form>
|
||||
```
|
||||
|
||||
```js
|
||||
const forms = document.querySelectorAll(".needs-validation");
|
||||
|
||||
// Loop over them and prevent submission
|
||||
Array.from(forms).forEach((form) => {
|
||||
form.querySelector("input").addEventListener("blur", (e) => {
|
||||
console.log("detected");
|
||||
form.classList.add("was-validated");
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
console.log("submit listened");
|
||||
// event.preventDefault();
|
||||
// if (!form.checkValidity()) {
|
||||
// console.log("preventing default");
|
||||
// event.preventDefault();
|
||||
// event.stopPropagation();
|
||||
// }
|
||||
|
||||
// form.classList.add("was-validated");
|
||||
});
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
|
||||
Using custom rules for validation
|
||||
Loading…
Reference in a new issue