i have the next function that validates the fields of a form, and I have other that creates a JSON. how can i modify the present code to insert the function that creates the JSON?
function validation() {
'use strict'
// Obtener todos los formularios a los que queremos aplicar estilos de validación de Bootstrap personalizados
var forms = document.querySelectorAll('.needs-validation');
console.log(forms);
// Bucle sobre ellos y evitar el envío
Array.prototype.slice.call(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
}
I try to modify the code by inserting my function (json) after the controls of events but it didn't work.