Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Add clear validation to or-input

Robin Dekkers942ac1db9425
diff --git a/ui/app/or-app/src/pages/page-users.ts b/ui/app/or-app/src/pages/page-users.ts
index 83f25c583..1c5924673 100644
--- a/ui/app/or-app/src/pages/page-users.ts
+++ b/ui/app/or-app/src/pages/page-users.ts
@@ -249,28 +249,24 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {
}
private checkPassword(index) {
-
-
const repeatPasswordComponent = this.shadowRoot.getElementById("repeatPassword-"+index) as OrInput
const passwordComponent = this.shadowRoot.getElementById("password-"+index)
const repeatPassword = repeatPasswordComponent.shadowRoot.querySelector('input');
const password = passwordComponent.shadowRoot.querySelector('input');
if(repeatPassword.value !== password.value) {
- if(repeatPasswordComponent) {
const error = i18next.t("samePassword");
repeatPassword.setCustomValidity(error);
repeatPasswordComponent.helperText = error;
- }
return false
} else {
if(repeatPasswordComponent) {
- repeatPassword.setCustomValidity("");
repeatPasswordComponent.helperText = ""
}
return password.value
}
}
+
private _createUser(user, index) {
const password = this.checkPassword(index)
manager.rest.api.UserResource.create(manager.displayRealm, user).then((response:any) => {
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index ecfaa12ee..2cfdf6ff7 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -1022,6 +1022,7 @@ export class OrInput extends LitElement {
if ((e.code === "Enter" || e.code === "NumpadEnter")) {
this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value);
}}}"
+ @input="${(e: Event) => this.clearValidation(e)}"
@change="${(e: Event) => this.onValueChange((e.target as HTMLInputElement), (e.target as HTMLInputElement).value)}" />`;
inputElem = html`
@@ -1182,6 +1183,11 @@ export class OrInput extends LitElement {
`;
}
+ protected clearValidation(e:Event){
+ const input = e.target as HTMLInputElement
+ if(input) input.setCustomValidity("");
+ }
+
protected onValueChange(elem: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | undefined, newValue: any | undefined) {
let valid = true;