29 lines
844 B
JavaScript
29 lines
844 B
JavaScript
/* global axios, bootstrap */
|
|
|
|
const contactAuthorsForm = document.querySelector('#contact-authors-form')
|
|
|
|
if (contactAuthorsForm) {
|
|
contactAuthorsForm.addEventListener('submit', async event => {
|
|
event.preventDefault()
|
|
if (!contactAuthorsForm.checkValidity()) {
|
|
event.stopPropagation()
|
|
contactAuthorsForm.classList.add('was-validated')
|
|
return
|
|
}
|
|
|
|
const payload = Object.fromEntries(new FormData(event.target))
|
|
const res = await axios.post(event.target.action, payload)
|
|
|
|
if (res.status === 201) {
|
|
contactAuthorsForm.reset()
|
|
contactAuthorsForm.classList.remove('was-validated')
|
|
|
|
const infoModal = document.getElementById('contact-authors-response')
|
|
if (infoModal) {
|
|
const responseModal = new bootstrap.Modal(infoModal)
|
|
responseModal.toggle()
|
|
}
|
|
}
|
|
})
|
|
}
|