This is an automated email from the ASF dual-hosted git repository. msciabarra pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/openserverless-vscode-extension.git
commit ddd5f7637059fa511cb08af3003b738748e3f978 Author: mattia-tatone <[email protected]> AuthorDate: Thu Mar 7 10:45:56 2024 +0100 multiple error message - Fix multiple error message - delete file main2.ts --- src/webview/main.ts | 15 ++++++++----- src/webview/main2.ts | 60 ---------------------------------------------------- 2 files changed, 10 insertions(+), 65 deletions(-) diff --git a/src/webview/main.ts b/src/webview/main.ts index af3aec0..e6c44ee 100644 --- a/src/webview/main.ts +++ b/src/webview/main.ts @@ -31,9 +31,10 @@ function main() { const submitButton = LoginPage.getLoginButton(); submitButton?.addEventListener("click", handleLoginSubmit) - LoginPage.getUsername().addEventListener("change", validateUsername); - LoginPage.getPassword().addEventListener("change", validatePassword); - LoginPage.getApiHost().addEventListener("change", validateApiHost); + LoginPage.getUsername().addEventListener("change", validateLogin); + LoginPage.getPassword().addEventListener("change", validateLogin); + LoginPage.getApiHost().addEventListener("change", validateLogin); + } catch (error: any) { console.error(error); sendError(error); @@ -103,7 +104,7 @@ const Validators = { function createErrorMessages(assertions: ValidatorAssertion[]) { try { - assertions.filter(a => a.isValid).forEach((assertion: ValidatorAssertion, i: number) => { + assertions.forEach((assertion: ValidatorAssertion, i: number) => { let { htmlElement } = assertion; htmlElement.classList.remove("input-error"); htmlElement.classList.add("input-success"); @@ -189,7 +190,11 @@ function validateApiHost() { function validateLogin() { try { const loginSubmitButton = LoginPage.getLoginButton(); - let isValid = validateUsername() && validatePassword() && validateApiHost(); + let isUsernameValid = validateUsername(); + let isPasswordValid = validatePassword(); + let isApiHostValid = validateApiHost(); + + let isValid = isUsernameValid && isPasswordValid && isApiHostValid; loginSubmitButton.disabled = !isValid; return isValid; } catch (error: any) { diff --git a/src/webview/main2.ts b/src/webview/main2.ts deleted file mode 100644 index a74e8dc..0000000 --- a/src/webview/main2.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { Button, provideVSCodeDesignSystem, vsCodeButton } from "@vscode/webview-ui-toolkit"; - -provideVSCodeDesignSystem().register(vsCodeButton()); -const vscode = acquireVsCodeApi(); -window.addEventListener("load", main); - -function main() { - try { - const submitButton = document.getElementById("login-submit") as Button; - submitButton?.addEventListener("click", handleLoginSubmit) - breakpoint("1"); - } catch (error: any) { - breakpoint(error.toString()); - console.error(error); - throw error; - } - // To get improved type annotations/IntelliSense the associated class for - // a given toolkit component can be imported and used to type cast a reference - // to the element (i.e. the `as Button` syntax) - -} - -function breakpoint(title: string) { - const submitButton = document.getElementById("login-submit") as Button; - submitButton.textContent = "Breakpoint " + title; -} - -function handleLoginSubmit() { - try { - breakpoint("2"); - const username = document.getElementById('username') as HTMLInputElement; - const password = document.getElementById('password') as HTMLInputElement; - const apiHost = document.getElementById('api-host') as HTMLInputElement; - - breakpoint("3"); - - if (username.value.trim() && password.value.trim() && apiHost.value.trim()) { - breakpoint("4A"); - vscode.postMessage({ - command: "login", - username: `${username.value}`, - password: `${password.value}`, - apiHost: `${apiHost.value}`, - text: `${username.value} ${password.value} ${apiHost.value} PASS`, - }); - breakpoint("5A"); - } else { - breakpoint("4B"); - vscode.postMessage({ - command: "login", - text: `${username.value} ${password.value} ${apiHost.value} NOT PASS`, - }); - breakpoint("5B"); - } - } catch (error: any) { - breakpoint(error?.toString()); - console.error(error); - throw error; - } -} \ No newline at end of file
