wip on password reset
This commit is contained in:
45
public/assets/js/fn.js
Normal file
45
public/assets/js/fn.js
Normal file
@@ -0,0 +1,45 @@
|
||||
function $_ID(id) {
|
||||
return document.getElementById(id)
|
||||
}
|
||||
|
||||
function getFormData(event) {
|
||||
return Object.fromEntries(new FormData(event.target).entries())
|
||||
}
|
||||
|
||||
function loopObject(obj, callback) {
|
||||
for (let [key, value] of Object.entries(obj)) {
|
||||
callback({ key, value })
|
||||
}
|
||||
}
|
||||
|
||||
async function postData(url = '', data = {}) {
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
cache: 'no-cache',
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
referrerPolicy: 'no-referrer',
|
||||
body: JSON.stringify(data)
|
||||
})
|
||||
|
||||
return response.json()
|
||||
}
|
||||
|
||||
function addValidationClasses(item) {
|
||||
$_ID(item.key).classList.add('form-input-border-error')
|
||||
$_ID(`${item.key}-error-box`).innerHTML = `<strong>${item.value}</strong>`
|
||||
}
|
||||
|
||||
function removeValidationClasess() {
|
||||
Array.from(document.getElementsByClassName('form-input-border-error')).forEach(element => {
|
||||
element.classList.remove('form-input-border-error')
|
||||
});
|
||||
|
||||
Array.from(document.getElementsByClassName('error-box')).forEach(element => {
|
||||
element.innerHTML = ''
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user