From 2ec70298872099a318ca7bdb3a9fd3d19a88d5e1 Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Wed, 14 Aug 2024 10:44:04 +0800 Subject: [PATCH] fix: #319 only allow confirm button when all the fields are filled in --- .../ModalAccountEditCreate.vue | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/views/AccountManagement/ModalAccountEditCreate.vue b/src/views/AccountManagement/ModalAccountEditCreate.vue index ef461bb..15facd7 100644 --- a/src/views/AccountManagement/ModalAccountEditCreate.vue +++ b/src/views/AccountManagement/ModalAccountEditCreate.vue @@ -265,6 +265,10 @@ export default defineComponent({ await router.push('/account-admin'); break; case MODAL_ACCT_EDIT: + await checkAccountIsUnique(); + if(!isAccountUnique.value) { + return; + } // 要注意的是舊的username跟新的username可以是不同的 await acctMgmtStore.editAccount( currentViewingUser.value.username, { @@ -305,31 +309,19 @@ export default defineComponent({ } } - onMounted(() => { - watch( - [inputUserAccount, inputName, inputPwd, inputConfirmPwd, isPwdMatched], - ([newAccount, newName, newPwd, newConfirmPwd, newPwdMatched]) => { - if (shouldDisalbeConfirmButton(newAccount, newName, newPwd, newConfirmPwd, newPwdMatched)) { - isConfirmDisabled.value = true; - } else { - isConfirmDisabled.value = false; - } - }, - { immediate: true } - ); - - watch( - [inputPwd, inputConfirmPwd], - ([newPwd, newConfirmPwd]) => { - isPwdMatched.value = newPwd === newConfirmPwd && newPwd.length; - isPwdLengthValid.value = newPwd.length >= PWD_VALID_LENGTH && newConfirmPwd.length >= PWD_VALID_LENGTH; - // 只要[確認密碼]或[密碼]有更動,confirm 按鈕就可點選 - if ((newPwd || newConfirmPwd) && inputUserAccount.length && inputName.length) { - isConfirmDisabled.value = false; - } + watch( + [inputPwd, inputConfirmPwd, inputUserAccount, inputName], + ([newPwd, newConfirmPwd, newAccount, newName]) => { + isPwdMatched.value = newPwd === newConfirmPwd && newPwd.length; + isPwdLengthValid.value = newPwd.length >= PWD_VALID_LENGTH && newConfirmPwd.length >= PWD_VALID_LENGTH; + // 只要[確認密碼]或[密碼]欄位有更動,且所有欄位都不是空的,confirm 按鈕就可點選 + if (newPwd.length > 0 && newConfirmPwd.length > 0 && newAccount.length > 0 && newName.length > 0) { + isConfirmDisabled.value = false; + } else { + isConfirmDisabled.value = true; } - ) - }); + } + ); return { isConfirmDisabled,