diff --git a/src/sql/base/parts/editableDropdown/browser/dropdown.ts b/src/sql/base/parts/editableDropdown/browser/dropdown.ts index df29c524f7..9e8152424d 100644 --- a/src/sql/base/parts/editableDropdown/browser/dropdown.ts +++ b/src/sql/base/parts/editableDropdown/browser/dropdown.ts @@ -139,7 +139,7 @@ export class Dropdown extends Disposable implements IListVirtualDelegate this._register(DOM.addStandardDisposableListener(this._input.inputElement, DOM.EventType.KEY_DOWN, (e: StandardKeyboardEvent) => { switch (e.keyCode) { case KeyCode.Enter: - if (this._input.validate()) { + if (this._input.validate() === undefined) { this._onValueChange.fire(this._input.value); } e.stopPropagation(); diff --git a/src/sql/workbench/browser/modal/optionsDialogHelper.ts b/src/sql/workbench/browser/modal/optionsDialogHelper.ts index 9c3afb3067..a35fbe1583 100644 --- a/src/sql/workbench/browser/modal/optionsDialogHelper.ts +++ b/src/sql/workbench/browser/modal/optionsDialogHelper.ts @@ -116,7 +116,7 @@ export function validateInputs(optionsMap: { [optionName: string]: IOptionElemen optionElement.option.valueType === ServiceOptionType.number); if (isInputBox) { - if (!widget.validate()) { + if (widget.validate() !== undefined) { isValid = false; if (!isFocused) { isFocused = true; diff --git a/src/sql/workbench/browser/modelComponents/inputbox.component.ts b/src/sql/workbench/browser/modelComponents/inputbox.component.ts index 0b2fd19646..037d60f2bb 100644 --- a/src/sql/workbench/browser/modelComponents/inputbox.component.ts +++ b/src/sql/workbench/browser/modelComponents/inputbox.component.ts @@ -159,7 +159,7 @@ export default class InputBoxComponent extends ComponentBase { await super.validate(); // Let the input validate handle showing/hiding the error message - const valid = this.inputElement.validate(); + const valid = this.inputElement.validate() === undefined; // set aria label based on validity of input if (valid) { diff --git a/src/sql/workbench/contrib/backup/browser/backup.component.ts b/src/sql/workbench/contrib/backup/browser/backup.component.ts index d5e2cd2168..c57296d10a 100644 --- a/src/sql/workbench/contrib/backup/browser/backup.component.ts +++ b/src/sql/workbench/contrib/backup/browser/backup.component.ts @@ -826,7 +826,7 @@ export class BackupComponent extends AngularDisposable { private enableBackupButton(): void { if (!this.backupButton!.enabled) { - if (this.pathListBox!.count > 0 && (!this.isFormatChecked || this.mediaNameBox!.value) && this.backupRetainDaysBox!.validate()) { + if (this.pathListBox!.count > 0 && (!this.isFormatChecked || this.mediaNameBox!.value) && this.backupRetainDaysBox!.validate() === undefined) { this.backupEnabled = true; } } @@ -851,7 +851,7 @@ export class BackupComponent extends AngularDisposable { } private backupRetainDaysChanged(days: string): void { - if (!this.backupRetainDaysBox!.validate()) { + if (this.backupRetainDaysBox!.validate() !== undefined) { this.backupEnabled = false; } else { this.enableBackupButton(); diff --git a/src/sql/workbench/services/connection/browser/connectionWidget.ts b/src/sql/workbench/services/connection/browser/connectionWidget.ts index dbdfa5f2a4..3444321037 100644 --- a/src/sql/workbench/services/connection/browser/connectionWidget.ts +++ b/src/sql/workbench/services/connection/browser/connectionWidget.ts @@ -887,27 +887,27 @@ export class ConnectionWidget extends lifecycle.Disposable { private validateInputs(): boolean { let isFocused = false; - let validateServerName = this._serverNameInputBox.validate(); - if (!validateServerName) { + const isServerNameValid = this._serverNameInputBox.validate() === undefined; + if (!isServerNameValid) { this._serverNameInputBox.focus(); isFocused = true; } - let validateUserName = this._userNameInputBox.validate(); - if (!validateUserName && !isFocused) { + const isUserNameValid = this._userNameInputBox.validate() === undefined; + if (!isUserNameValid && !isFocused) { this._userNameInputBox.focus(); isFocused = true; } - let validatePassword = this._passwordInputBox.validate(); - if (!validatePassword && !isFocused) { + const isPasswordValid = this._passwordInputBox.validate() === undefined; + if (!isPasswordValid && !isFocused) { this._passwordInputBox.focus(); isFocused = true; } - let validateAzureAccount = this.validateAzureAccountSelection(); - if (!validateAzureAccount && !isFocused) { + const isAzureAccountValid = this.validateAzureAccountSelection(); + if (!isAzureAccountValid && !isFocused) { this._azureAccountDropdown.focus(); isFocused = true; } - return validateServerName && validateUserName && validatePassword && validateAzureAccount; + return isServerNameValid && isUserNameValid && isPasswordValid && isAzureAccountValid; } public connect(model: IConnectionProfile): boolean { diff --git a/src/sql/workbench/services/serverGroup/browser/serverGroupDialog.ts b/src/sql/workbench/services/serverGroup/browser/serverGroupDialog.ts index ee41008c68..d48858a773 100644 --- a/src/sql/workbench/services/serverGroup/browser/serverGroupDialog.ts +++ b/src/sql/workbench/services/serverGroup/browser/serverGroupDialog.ts @@ -307,11 +307,11 @@ export class ServerGroupDialog extends Modal { private validateInputs(): boolean { const renderedDialog = this.withRenderedDialog; - let validate = renderedDialog.groupNameInputBox.validate(); - if (!validate) { + const isNameValid = renderedDialog.groupNameInputBox.validate() === undefined; + if (!isNameValid) { renderedDialog.groupNameInputBox.focus(); } - return validate; + return isNameValid; } // initialize the view based on the current state of the view model diff --git a/src/sql/workbench/test/browser/modal/optionsDialogHelper.test.ts b/src/sql/workbench/test/browser/modal/optionsDialogHelper.test.ts index 067a8f4cc9..f4b1675a70 100644 --- a/src/sql/workbench/test/browser/modal/optionsDialogHelper.test.ts +++ b/src/sql/workbench/test/browser/modal/optionsDialogHelper.test.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as OptionsDialogHelper from 'sql/workbench/browser/modal/optionsDialogHelper'; -import { InputBox } from 'vs/base/browser/ui/inputbox/inputBox'; +import { InputBox, MessageType } from 'vs/base/browser/ui/inputbox/inputBox'; import * as azdata from 'azdata'; import * as TypeMoq from 'typemoq'; import * as assert from 'assert'; @@ -100,7 +100,7 @@ suite('Advanced options helper tests', () => { inputBox = TypeMoq.Mock.ofType(InputBox, TypeMoq.MockBehavior.Loose, $('div'), null, null); inputBox.callBase = true; - inputBox.setup(x => x.validate()).returns(() => isValid); + inputBox.setup(x => x.validate()).returns(() => isValid ? undefined : MessageType.ERROR); inputBox.setup(x => x.value).returns(() => inputValue); }); diff --git a/src/vs/base/browser/ui/inputbox/inputBox.ts b/src/vs/base/browser/ui/inputbox/inputBox.ts index bf459bdf75..aa9b9a5f66 100644 --- a/src/vs/base/browser/ui/inputbox/inputBox.ts +++ b/src/vs/base/browser/ui/inputbox/inputBox.ts @@ -425,7 +425,7 @@ export class InputBox extends Widget { return !!this.validation && !this.validation(this.value); } - public validate(): boolean { // {{SQL CARBON EDIT}} + public validate(): MessageType | undefined { let errorMsg: IMessage | null = null; if (this.validation) { @@ -449,8 +449,7 @@ export class InputBox extends Widget { } } - // {{SQL CARBON EDIT}} Candidate for addition to vscode - return errorMsg ? errorMsg.type !== MessageType.ERROR : true; + return errorMsg?.type; } public stylesForType(type: MessageType | undefined): { border: Color | undefined; background: Color | undefined; foreground: Color | undefined } { diff --git a/src/vs/workbench/contrib/remote/browser/tunnelView.ts b/src/vs/workbench/contrib/remote/browser/tunnelView.ts index d8fae6777c..62595f2642 100644 --- a/src/vs/workbench/contrib/remote/browser/tunnelView.ts +++ b/src/vs/workbench/contrib/remote/browser/tunnelView.ts @@ -342,7 +342,7 @@ class TunnelTreeRenderer extends Disposable implements ITreeRenderer { if (e.equals(KeyCode.Enter)) { - if (inputBox.validate()) { // {{SQL CARBON EDIT}} + if (inputBox.validate() !== MessageType.ERROR) { done(true, true); } else { done(false, true); @@ -352,7 +352,7 @@ class TunnelTreeRenderer extends Disposable implements ITreeRenderer { - done(inputBox.validate(), true); // {{SQL CARBON EDIT}} + done(inputBox.validate() !== MessageType.ERROR, true); }), styler ];