5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 04:46:22 +00:00
panel/app/assets/javascripts/validation.js

36 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-11-20 00:23:23 +00:00
document.addEventListener('turbolinks:load', () => {
// 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'))
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()
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')
})
})
})