HM-79. Добавлена работа формы с ручкой, валидация формы. HM-88. Добавлены пункты меню с js. HM-76. Добавлена подсветка элементов меню (#40)
This commit is contained in:
@ -10,6 +10,7 @@ class FormControl extends Component {
|
||||
placeholder = '',
|
||||
initValue = '',
|
||||
className = '',
|
||||
required = false,
|
||||
} = {}) {
|
||||
super('#form-control', parentNode);
|
||||
|
||||
@ -19,6 +20,10 @@ class FormControl extends Component {
|
||||
tagName: this.getInputTagName(type),
|
||||
options: {
|
||||
className: `form-control ${className}`,
|
||||
},
|
||||
args: {
|
||||
type: type === FORM_TYPES.PASSWORD ? 'password' : 'text',
|
||||
...(required ? {required: ''} : {}),
|
||||
}
|
||||
});
|
||||
this.input.placeholder = placeholder;
|
||||
@ -28,6 +33,10 @@ class FormControl extends Component {
|
||||
this.label.insertAdjacentElement('afterend', this.input);
|
||||
this.label.textContent = label;
|
||||
this.label.setAttribute('for', id);
|
||||
|
||||
this.addEventListener(this.input, 'focus', this.clearError);
|
||||
this.addEventListener(this.input, 'click', this.clearError);
|
||||
this.addEventListener(this.input, 'keydown', this.clearError);
|
||||
}
|
||||
|
||||
disabled = (value) => {
|
||||
@ -42,6 +51,14 @@ class FormControl extends Component {
|
||||
this.input.value = value;
|
||||
}
|
||||
|
||||
setError = (errorMessage) => {
|
||||
this.errorText.textContent = errorMessage;
|
||||
}
|
||||
|
||||
clearError = () => {
|
||||
this.errorText.textContent = '';
|
||||
}
|
||||
|
||||
getInputTagName (type) {
|
||||
switch (type) {
|
||||
case FORM_TYPES.TEXT:
|
||||
|
||||
Reference in New Issue
Block a user