feat(frontend): clear input fields on success
This commit is contained in:
parent
94d617e551
commit
ee432e256f
@ -70,13 +70,26 @@ function hideModal() {
|
||||
|
||||
FIELDS = ['username', 'old_password', 'new_password']
|
||||
|
||||
function mapFields(thunk) {
|
||||
for (fieldIndex in FIELDS) {
|
||||
let fieldName = FIELDS[fieldIndex]
|
||||
let field = document.querySelectorAll(`input[name=${fieldName}]`)[0];
|
||||
thunk(field, fieldName);
|
||||
}
|
||||
}
|
||||
|
||||
function clearFields() {
|
||||
mapFields(field => {
|
||||
field.value = "";
|
||||
});
|
||||
}
|
||||
|
||||
function changePasswords() {
|
||||
let query = {};
|
||||
|
||||
for (field in FIELDS) {
|
||||
let selector = `input[name=${FIELDS[field]}]`;
|
||||
query[FIELDS[field]] = document.querySelectorAll(selector)[0].value;
|
||||
}
|
||||
mapFields((field, fieldName) => {
|
||||
query[fieldName] = field.value;
|
||||
});
|
||||
|
||||
showModal("Wait");
|
||||
|
||||
@ -92,6 +105,7 @@ function changePasswords() {
|
||||
}).then(response => {
|
||||
if(response.success) {
|
||||
showModal("Success");
|
||||
clearFields();
|
||||
} else {
|
||||
showModal(response.message);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user