Skip to content

armgit / core

Public Imported from GitHub
0

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

UI updates: bug fix for or-input validation

Rich Turner485fa8c59614
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.json
index 7ea1435b1..1239bcc7e 100644
--- a/deployment/manager/shared/locales/en/or.json
+++ b/deployment/manager/shared/locales/en/or.json
@@ -196,7 +196,7 @@
"user_role": "Role",
"role_plural": "Roles",
"description": "Description",
- "samePassword":"Password are not the same",
+ "passwordMismatch":"Passwords do not match",
"username":"Username",
"firstName":"First name",
"surname":"Surname",
diff --git a/deployment/manager/shared/locales/nl/or.json b/deployment/manager/shared/locales/nl/or.json
index 42513ae1b..492c9cc16 100644
--- a/deployment/manager/shared/locales/nl/or.json
+++ b/deployment/manager/shared/locales/nl/or.json
@@ -199,7 +199,7 @@
"username":"Gebruikersnaam",
"deleteUserConfirm":"Deze gebruiker verwijderen?",
"deleteRoleConfirm":"Deze rol verwijderen?",
- "samePassword":"Wachtwoorden komen niet overeen",
+ "passwordMismatch":"Wachtwoorden komen niet overeen",
"firstName":"Voornaam",
"surname":"Achternaam",
"realmRules": "Realm regels",
diff --git a/ui/app/or-app/src/pages/page-users.ts b/ui/app/or-app/src/pages/page-users.ts
index ff5136758..1f26f1afa 100644
--- a/ui/app/or-app/src/pages/page-users.ts
+++ b/ui/app/or-app/src/pages/page-users.ts
@@ -249,21 +249,20 @@ 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) {
- const error = i18next.t("samePassword");
- repeatPassword.setCustomValidity(error);
+ const repeatPasswordComponent = this.shadowRoot.getElementById("repeatPassword-"+index) as OrInput;
+ const passwordComponent = this.shadowRoot.getElementById("password-"+index) as OrInput;
+
+ if (repeatPasswordComponent.value !== passwordComponent.value) {
+ const error = i18next.t("passwordMismatch");
+ repeatPasswordComponent.validationMessage = error;
+ repeatPasswordComponent.setCustomValidity(error);
repeatPasswordComponent.helperText = error;
- return false
+ return false;
} else {
- if(repeatPasswordComponent) {
- repeatPasswordComponent.helperText = ""
+ if (repeatPasswordComponent) {
+ repeatPasswordComponent.helperText = "";
}
- return password.value
+ return passwordComponent.value;
}
}
diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.ts
index 4d8566357..ec0b95366 100644
--- a/ui/component/or-input/src/index.ts
+++ b/ui/component/or-input/src/index.ts
@@ -710,6 +710,17 @@ export class OrInput extends LitElement {
}
}
+ public setCustomValidity(msg?: string) {
+ const elem = this.shadowRoot!.getElementById("elem") as HTMLElement;
+ if (!elem || !(elem as any).setCustomValidity) {
+ return;
+ }
+ (elem as any).setCustomValidity(msg);
+ if (this._mdcComponent && (this._mdcComponent as any).valid) {
+ (this._mdcComponent as any).valid = (elem as any).checkValidity();
+ }
+ }
+
protected render() {
if (this.type) {
@@ -893,7 +904,8 @@ export class OrInput extends LitElement {
return html`
<div id="field" class="mdc-form-field">
<div id="component" class="mdc-checkbox">
- <input type="checkbox"
+ <input type="checkbox"
+ id="elem"
?checked="${this.value && this.value.includes(optValue)}"
?required="${this.required}"
name="${optValue}"
@@ -915,6 +927,7 @@ export class OrInput extends LitElement {
<div id="field" class="mdc-form-field">
<div id="component" class="mdc-checkbox">
<input type="checkbox"
+ id="elem"
?checked="${this.value}"
?required="${this.required}"
?disabled="${this.disabled || this.readonly}"
@@ -1070,7 +1083,7 @@ export class OrInput extends LitElement {
<span id="wrapper">
${this.label ? html`<label for="component" class="${this.disabled ? "mdc-switch--disabled" : ""}">${this.label}</label>` : ``}
<div id="component" class="${classMap(classes)}" @MDCSlider:change="${(ev:CustomEvent<MDCSliderChangeEventDetail>) => this.onValueChange(undefined, ev.detail.value)}">
- <input class="mdc-slider__input" type="range" min="${ifDefined(valMinMax[1])}" max="${ifDefined(valMinMax[2])}" value="${valMinMax[0] || valMinMax[1] || 0}" name="slider" step="${this.step || 1}" ?readonly="${this.readonly}" ?disabled="${this.disabled}" aria-label="${ifDefined(this.label)}" />
+ <input id="elem" class="mdc-slider__input" type="range" min="${ifDefined(valMinMax[1])}" max="${ifDefined(valMinMax[2])}" value="${valMinMax[0] || valMinMax[1] || 0}" name="slider" step="${this.step || 1}" ?readonly="${this.readonly}" ?disabled="${this.disabled}" aria-label="${ifDefined(this.label)}" />
<div class="mdc-slider__track">
<div class="mdc-slider__track--inactive"></div>
<div class="mdc-slider__track--active">