Add new component, add flags on filter
This commit is contained in:
74
resources/views/load/form/validator.js
Normal file
74
resources/views/load/form/validator.js
Normal file
@@ -0,0 +1,74 @@
|
||||
function initValidator() {
|
||||
$( document ).ready(function() {
|
||||
// console.log('initValidator');
|
||||
// $(window).on('load', function() {
|
||||
// window.addEventListener('load', function() {
|
||||
|
||||
// console.log('initValidator load');
|
||||
var forms = $('.needs-validation');
|
||||
|
||||
$(forms).each(function(i, form) {
|
||||
form.addEventListener('submit', function(event) {
|
||||
checkValidatorFields(form);
|
||||
}, false);
|
||||
});
|
||||
|
||||
// }, false);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidatorFields(form) {
|
||||
console.log('checkValidatorFields');
|
||||
if (form.checkValidity() === false) {
|
||||
console.log('non validé');
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
} else {
|
||||
console.log("validé");
|
||||
form.classList.add('valid');
|
||||
}
|
||||
form.classList.add('was-validated');
|
||||
|
||||
form.addEventListener('invalid', function(e) {
|
||||
console.log(e);
|
||||
}, true);
|
||||
|
||||
}
|
||||
|
||||
function initValidatorHtml() {
|
||||
window.addEventListener('load', function() {
|
||||
// Fetch all the forms we want to apply custom Bootstrap validation styles to
|
||||
var forms = document.getElementsByClassName('needs-validation');
|
||||
// Loop over them and prevent submission
|
||||
var validation = Array.prototype.filter.call(forms, function(form) {
|
||||
form.addEventListener('submit', function(event) {
|
||||
if (form.checkValidity() === false) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
form.classList.add('was-validated');
|
||||
}, false);
|
||||
});
|
||||
}, false);
|
||||
}
|
||||
|
||||
function initValidator2() {
|
||||
$('.needs-validation').bootstrapValidator().on('submit', function(e) {
|
||||
if (e.isDefaultPrevented()) {
|
||||
console.log('bad');
|
||||
} else {
|
||||
console.log('good');
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
// Active the panel element containing the first invalid element
|
||||
var $form = $(e.target),
|
||||
validator = $form.data('bootstrapValidator'),
|
||||
$invalidField = validator.getInvalidFields().eq(0),
|
||||
$collapse = $invalidField.parents('.collapse');
|
||||
|
||||
$collapse.collapse('show');
|
||||
});
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user