57 lines
2.1 KiB
JavaScript
57 lines
2.1 KiB
JavaScript
(function () {
|
|
var currentPasswordInput = document.querySelector('[data-account-current-password]');
|
|
var profileFormInput = document.querySelector('[data-account-profile-current-password]');
|
|
var passwordFormInput = document.querySelector('[data-account-password-current-password]');
|
|
var profileForm = profileFormInput && profileFormInput.form;
|
|
var passwordForm = passwordFormInput && passwordFormInput.form;
|
|
|
|
if (!currentPasswordInput || !profileFormInput || !passwordFormInput || !profileForm || !passwordForm) {
|
|
return;
|
|
}
|
|
|
|
function syncCurrentPassword() {
|
|
profileFormInput.value = currentPasswordInput.value;
|
|
passwordFormInput.value = currentPasswordInput.value;
|
|
}
|
|
|
|
function clearCurrentPassword() {
|
|
currentPasswordInput.value = '';
|
|
currentPasswordInput.setCustomValidity('');
|
|
currentPasswordInput.removeAttribute('required');
|
|
profileFormInput.value = '';
|
|
passwordFormInput.value = '';
|
|
passwordForm.querySelectorAll('input[type="password"]').forEach(function (input) {
|
|
input.value = '';
|
|
input.setCustomValidity('');
|
|
});
|
|
profileForm.classList.remove('was-validated');
|
|
passwordForm.classList.remove('was-validated');
|
|
}
|
|
|
|
currentPasswordInput.addEventListener('input', syncCurrentPassword);
|
|
currentPasswordInput.addEventListener('input', function () {
|
|
currentPasswordInput.setCustomValidity('');
|
|
});
|
|
document.addEventListener('submit', function (event) {
|
|
if (event.target !== profileForm && event.target !== passwordForm) {
|
|
return;
|
|
}
|
|
if (!currentPasswordInput.value) {
|
|
event.preventDefault();
|
|
event.stopImmediatePropagation();
|
|
currentPasswordInput.setCustomValidity('Current password is required.');
|
|
currentPasswordInput.reportValidity();
|
|
return;
|
|
}
|
|
currentPasswordInput.setCustomValidity('');
|
|
syncCurrentPassword();
|
|
}, true);
|
|
passwordForm.addEventListener('submit', syncCurrentPassword);
|
|
document.addEventListener('web-async-save:success', function (event) {
|
|
if (event.detail && event.detail.form !== profileForm && event.detail.form !== passwordForm) {
|
|
return;
|
|
}
|
|
clearCurrentPassword();
|
|
});
|
|
})();
|