Add required value validations for checkbox and dropdown (#9770)

This commit is contained in:
Charles Gagnon
2020-03-30 12:44:56 -07:00
committed by GitHub
parent 90277d627c
commit 9b641490ea
3 changed files with 16 additions and 6 deletions

View File

@@ -74,30 +74,34 @@ export default class DropDownComponent extends ComponentBase implements ICompone
this._register(this._editableDropdown);
this._register(attachEditableDropdownStyler(this._editableDropdown, this.themeService));
this._register(this._editableDropdown.onValueChange(e => {
this._register(this._editableDropdown.onValueChange(async e => {
if (this.editable) {
this.setSelectedValue(this._editableDropdown.value);
await this.validate();
this.fireEvent({
eventType: ComponentEventType.onDidChange,
args: e
});
}
}));
this._validations.push(() => !this.required || !this.editable || !!this._editableDropdown.value);
}
if (this._dropDownContainer) {
this._selectBox = new SelectBox(this.getValues(), this.getSelectedValue(), this.contextViewService, this._dropDownContainer.nativeElement);
this._selectBox.render(this._dropDownContainer.nativeElement);
this._register(this._selectBox);
this._register(attachSelectBoxStyler(this._selectBox, this.themeService));
this._register(this._selectBox.onDidSelect(e => {
this._register(this._selectBox.onDidSelect(async e => {
if (!this.editable) {
this.setSelectedValue(this._selectBox.value);
await this.validate();
this.fireEvent({
eventType: ComponentEventType.onDidChange,
args: e
});
}
}));
this._validations.push(() => !this.required || this.editable || !!this._selectBox.value);
}
}
@@ -139,6 +143,7 @@ export default class DropDownComponent extends ComponentBase implements ICompone
this._selectBox.selectElem.required = this.required;
this._editableDropdown.inputElement.required = this.required;
this.validate();
}
private getValues(): string[] {