Add validation to model view components (#1356)

This commit is contained in:
Matt Irvine
2018-05-08 14:15:26 -07:00
committed by GitHub
parent c2b32fd64a
commit f10e281ffc
18 changed files with 459 additions and 35 deletions

View File

@@ -10,10 +10,11 @@ import {
import * as sqlops from 'sqlops';
import Event, { Emitter } from 'vs/base/common/event';
import * as nls from 'vs/nls';
import { ComponentBase } from 'sql/parts/modelComponents/componentBase';
import { IComponent, IComponentDescriptor, IModelStore, ComponentEventType } from 'sql/parts/modelComponents/interfaces';
import { InputBox, IInputOptions } from 'vs/base/browser/ui/inputbox/inputBox';
import { InputBox, IInputOptions, MessageType } from 'vs/base/browser/ui/inputbox/inputBox';
import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service';
import { attachInputBoxStyler, attachListStyler } from 'vs/platform/theme/common/styler';
@@ -44,7 +45,19 @@ export default class InputBoxComponent extends ComponentBase implements ICompone
if (this._inputContainer) {
let inputOptions: IInputOptions = {
placeholder: '',
ariaLabel: ''
ariaLabel: '',
validationOptions: {
validation: () => {
if (this.valid) {
return undefined;
} else {
return {
content: nls.localize('invalidValueError', 'Invalid value'),
type: MessageType.ERROR
};
}
}
}
};
this._input = new InputBox(this._inputContainer.nativeElement, this._commonService.contextViewService, inputOptions);
@@ -81,6 +94,11 @@ export default class InputBoxComponent extends ComponentBase implements ICompone
this._input.value = this.value;
}
public setValid(valid: boolean): void {
super.setValid(valid);
this._input.validate();
}
// CSS-bound properties
public get value(): string {