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

@@ -32,7 +32,7 @@ export default class CheckBoxComponent extends ComponentBase implements ICompone
constructor(
@Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef,
@Inject(IWorkbenchThemeService) private themeService: IWorkbenchThemeService,
@Inject(forwardRef(() => ElementRef)) el: ElementRef,) {
@Inject(forwardRef(() => ElementRef)) el: ElementRef) {
super(changeRef, el);
}
@@ -50,14 +50,16 @@ export default class CheckBoxComponent extends ComponentBase implements ICompone
this._input = new Checkbox(this._inputContainer.nativeElement, inputOptions);
this._register(this._input);
this._register(this._input.onChange(e => {
this._register(this._input.onChange(async e => {
this.checked = this._input.checked;
await this.validate();
this.fireEvent({
eventType: ComponentEventType.onDidChange,
args: e
});
}));
this._register(attachCheckboxStyler(this._input, this.themeService));
this._validations.push(() => !this.required || this.checked);
}
}
@@ -93,6 +95,7 @@ export default class CheckBoxComponent extends ComponentBase implements ICompone
if (this.required) {
this._input.required = this.required;
}
this.validate();
}
// CSS-bound properties

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[] {