joplin-notes/joplin notion extension/Web Development/CSS/Bootstrap/validation.md
2026-11-04 00:33:23 +05:30

42 lines
No EOL
921 B
Markdown

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");
});
});
```
&nbsp;
Using custom rules for validation