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']
|
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() {
|
function changePasswords() {
|
||||||
let query = {};
|
let query = {};
|
||||||
|
|
||||||
for (field in FIELDS) {
|
mapFields((field, fieldName) => {
|
||||||
let selector = `input[name=${FIELDS[field]}]`;
|
query[fieldName] = field.value;
|
||||||
query[FIELDS[field]] = document.querySelectorAll(selector)[0].value;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
showModal("Wait");
|
showModal("Wait");
|
||||||
|
|
||||||
@ -92,6 +105,7 @@ function changePasswords() {
|
|||||||
}).then(response => {
|
}).then(response => {
|
||||||
if(response.success) {
|
if(response.success) {
|
||||||
showModal("Success");
|
showModal("Success");
|
||||||
|
clearFields();
|
||||||
} else {
|
} else {
|
||||||
showModal(response.message);
|
showModal(response.message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user