CJVT updates August and September 2026
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/* global axios, i18next */
|
||||
|
||||
function displayError(errorElementId, error) {
|
||||
let message = i18next.t('Prišlo je do napake.')
|
||||
if (error.response) {
|
||||
message = error.response.data
|
||||
} else if (error.request) {
|
||||
message = i18next.t('Strežnik ni dosegljiv. Poskusite kasneje.')
|
||||
}
|
||||
|
||||
const errorElement = document.querySelector(`#${errorElementId}`)
|
||||
errorElement.textContent = message
|
||||
errorElement.style.visibility = 'visible'
|
||||
}
|
||||
|
||||
function bindAjaxForm(formId, errorElementId) {
|
||||
const form = document.querySelector(`#${formId}`)
|
||||
if (!form) return
|
||||
|
||||
form.addEventListener('submit', async event => {
|
||||
event.preventDefault()
|
||||
|
||||
const data = {}
|
||||
new FormData(form).forEach((value, key) => {
|
||||
data[key] = value
|
||||
})
|
||||
|
||||
try {
|
||||
await axios.post(form.action, data)
|
||||
window.location = '/'
|
||||
} catch (error) {
|
||||
displayError(errorElementId, error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
bindAjaxForm('create-profile-form', 'create-profile-error')
|
||||
bindAjaxForm('convert-account-form', 'convert-account-error')
|
||||
Reference in New Issue
Block a user