From 770f46b5e5a6a5673056daac23a05597c6cddf74 Mon Sep 17 00:00:00 2001 From: Nikolay <46225163+vigdorov@users.noreply.github.com> Date: Sun, 30 Aug 2020 19:44:46 +0300 Subject: [PATCH] =?UTF-8?q?HM-102.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B2=D0=B5=D0=B7=D0=B4=D0=BE?= =?UTF-8?q?=D1=87=D0=B5=D0=BA=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1=D1=8F?= =?UTF-8?q?=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=B5=D0=B9=20(#63)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.html | 2 +- src/components/form-control/FormControl.js | 9 ++++++++- src/components/user-view-form/UserViewForm.js | 11 +++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/app.html b/src/app.html index 9627db9..4252db2 100644 --- a/src/app.html +++ b/src/app.html @@ -433,7 +433,7 @@ diff --git a/src/components/form-control/FormControl.js b/src/components/form-control/FormControl.js index afd6599..ce4fa7c 100644 --- a/src/components/form-control/FormControl.js +++ b/src/components/form-control/FormControl.js @@ -16,6 +16,8 @@ class FormControl extends Component { super('#form-control', parentNode); this.label = this.mainNode.querySelector('.form-label'); + this.labelText = this.mainNode.querySelector('.FormControl__label'); + this.star = this.mainNode.querySelector('.FormControl__star'); this.errorText = this.mainNode.querySelector('.form-text'); this.input = this.createElement({ tagName: this.getInputTagName(type), @@ -33,7 +35,7 @@ class FormControl extends Component { this.input.value = initValue; this.label.insertAdjacentElement('afterend', this.input); - this.label.textContent = label; + this.labelText.textContent = label; this.label.setAttribute('for', id); this.addEventListener(this.input, EVENTS.FOCUS, this.clearError); @@ -43,6 +45,10 @@ class FormControl extends Component { this.next(EVENTS.INPUT, evt); }); + if (required) { + this.star.textContent = ' *'; + } + if (type === FORM_TYPES.SELECT) { options.forEach(({value, text}) => { this.createElement({ @@ -64,6 +70,7 @@ class FormControl extends Component { } disabled = (value) => { + this.star.style.visibility = value ? 'hidden' : 'visible'; this.input.disabled = value; } diff --git a/src/components/user-view-form/UserViewForm.js b/src/components/user-view-form/UserViewForm.js index 6a54915..89981d9 100644 --- a/src/components/user-view-form/UserViewForm.js +++ b/src/components/user-view-form/UserViewForm.js @@ -38,6 +38,7 @@ class UserViewForm extends Component { this.password = this.createComponent(FormControl, this.form, { id: 'user-view-form-password', label: 'Пароль', + required: true, type: FORM_TYPES.PASSWORD, }), this.avatar = this.createComponent(FormControl, this.form, { @@ -151,6 +152,14 @@ class UserViewForm extends Component { return this.form.checkValidity(); } + clearForm = () => { + this.form.classList.remove('was-validated'); + this.login.setValue(''); + this.avatar.setValue(''); + this.password.setValue(''); + this.isAdmin.setValue(false); + } + createUser = () => { if (this.validateInputs()) { this.next(EVENTS.CREATE_USER, { @@ -159,6 +168,7 @@ class UserViewForm extends Component { password: this.password.getValue(), is_admin: this.isAdmin.getValue() === TRUE, }); + this.clearForm(); routeService.pushQuery({}, true); } } @@ -170,6 +180,7 @@ class UserViewForm extends Component { avatar: this.avatar.getValue(), is_admin: this.isAdmin.getValue() === TRUE, }); + this.clearForm(); routeService.pushQuery({}, true); } }