diff --git a/src/static/webldappasswd.js b/src/static/webldappasswd.js index bf8bf44..c5c604d 100644 --- a/src/static/webldappasswd.js +++ b/src/static/webldappasswd.js @@ -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); }