2020-11-20 00:23:23 +00:00
|
|
|
document.addEventListener('turbolinks:load', () => {
|
2019-08-13 19:09:23 +00:00
|
|
|
// Al enviar el formulario del artículo, aplicar la validación
|
2020-11-20 00:23:23 +00:00
|
|
|
// localmente y actualizar los comentarios para lectores de pantalla.
|
|
|
|
document.querySelectorAll('.submit-post').forEach(submit => {
|
|
|
|
submit.addEventListener('click', event => {
|
|
|
|
const form = submit.closest('form')
|
|
|
|
const invalid_help = form.querySelectorAll('.invalid_help')
|
|
|
|
const sending_help = form.querySelectorAll('.sending_help')
|
|
|
|
|
|
|
|
invalid_help.forEach(i => i.classList.add('d-none'))
|
|
|
|
sending_help.forEach(i => i.classList.add('d-none'))
|
2018-12-14 13:32:35 +00:00
|
|
|
|
2020-11-20 00:23:23 +00:00
|
|
|
form.querySelectorAll('[aria-invalid="true"]').forEach(aria => {
|
|
|
|
aria.setAttribute('aria-invalid', false)
|
|
|
|
aria.setAttribute('aria-describedby', aria.parentElement.querySelector('.feedback').id)
|
|
|
|
})
|
2018-06-15 22:13:18 +00:00
|
|
|
|
2020-11-20 00:23:23 +00:00
|
|
|
if (form.checkValidity() === false) {
|
|
|
|
event.preventDefault()
|
|
|
|
event.stopPropagation()
|
2019-08-13 19:09:23 +00:00
|
|
|
|
2020-11-20 00:23:23 +00:00
|
|
|
invalid_help.forEach(i => i.classList.remove('d-none'))
|
2018-06-15 22:13:18 +00:00
|
|
|
|
2020-11-20 00:23:23 +00:00
|
|
|
form.querySelectorAll(':invalid').forEach(invalid => {
|
|
|
|
invalid.setAttribute('aria-invalid', true)
|
|
|
|
invalid.setAttribute('aria-describedby', invalid.parentElement.querySelector('.invalid-feedback').id)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
sending_help.forEach(i => i.classList.remove('d-none'))
|
|
|
|
}
|
2018-12-14 15:12:17 +00:00
|
|
|
|
2020-11-20 00:23:23 +00:00
|
|
|
form.classList.add('was-validated')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|