mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 20:01:31 +00:00
Fix naming and some function in commonLoginRegisterView file
This commit is contained in:
@@ -8,7 +8,10 @@ export default class CommonLoginRegisterView extends CommonView {
|
|||||||
|
|
||||||
this.parentElement = document.querySelector('.form');
|
this.parentElement = document.querySelector('.form');
|
||||||
this.messageDefault = CONSTANT.MESSAGE.ERROR_MESSAGE_DEFAULT;
|
this.messageDefault = CONSTANT.MESSAGE.ERROR_MESSAGE_DEFAULT;
|
||||||
this.inputField = document.querySelectorAll('.form__input');
|
this.inputPassword = document.querySelector('input[name="password"]');
|
||||||
|
this.inputPasswordConfirm = document.querySelector(
|
||||||
|
'input[name="password_confirm"]',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,43 +44,24 @@ export default class CommonLoginRegisterView extends CommonView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show error style input password
|
* Show or hide style error input password
|
||||||
*/
|
*/
|
||||||
changeToStyleErrorInputPassword() {
|
toogleErrorStyleInputPass() {
|
||||||
// Index = 1 because it should skip email input field
|
this.inputPassword.classList.toggle('error-input');
|
||||||
for (let index = 1; index < this.inputField.length; index += 1) {
|
this.inputPasswordConfirm.classList.toggle('error-input');
|
||||||
this.inputField[index].style.background = '#ffc3c3';
|
|
||||||
this.inputField[index].style.borderColor = '#ce1414';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear error style input password
|
|
||||||
*/
|
|
||||||
clearStyleErrorInputPassword() {
|
|
||||||
for (let index = 1; index < this.inputField.length; index += 1) {
|
|
||||||
this.inputField[index].style.background = '#f5f5f5';
|
|
||||||
this.inputField[index].style.borderColor = '#f5f5f5';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reassign again to check error message element haved on page or not
|
|
||||||
*/
|
|
||||||
reassignVariableErrorMessage() {
|
|
||||||
this.errorMessage = document.querySelector('.form__error-message');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear error message at form
|
* Clear error message at form
|
||||||
*/
|
*/
|
||||||
clearErrorMessage() {
|
clearErrorMessage() {
|
||||||
this.reassignVariableErrorMessage();
|
// Reassign again to check error message element haved on page or not
|
||||||
|
this.errorMessageEl = document.querySelector('.form__error-message');
|
||||||
|
|
||||||
// If have error message on page, remove it
|
// If have error message on page, remove it
|
||||||
if (this.errorMessage) {
|
if (this.errorMessageEl) {
|
||||||
this.errorMessage.remove();
|
this.errorMessageEl.remove();
|
||||||
this.clearStyleErrorInputPassword();
|
this.toogleErrorStyleInputPass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,12 +80,12 @@ export default class CommonLoginRegisterView extends CommonView {
|
|||||||
*/
|
*/
|
||||||
showError(message) {
|
showError(message) {
|
||||||
this.renderError(message);
|
this.renderError(message);
|
||||||
this.changeToStyleErrorInputPassword();
|
this.toogleErrorStyleInputPass();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show error message in form
|
* Show error message in form
|
||||||
* @param {*} message The message will show in form
|
* @param {string} message The message will show in form
|
||||||
*/
|
*/
|
||||||
renderError(message) {
|
renderError(message) {
|
||||||
const markup = `
|
const markup = `
|
||||||
|
|||||||
@@ -83,3 +83,8 @@
|
|||||||
color: $primary-color;
|
color: $primary-color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error-input {
|
||||||
|
border: 2px solid $dark-error-color;
|
||||||
|
background-color: $light-error-color;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user