From 2bb23a5c6cb57651c3171f8ab65a16bf0028ed9e Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Thu, 2 Aug 2018 10:38:07 +0200 Subject: [PATCH] ui: Fix boolean and switch widgets (if multiple) Previously UI item's ids were duplicated, the observed consequence is that any click on widgets is catched by 1st declared element. For example, a thing with 2 switches is displayed correctly, and click events are also triggered but event will be "redirected" to 1st switch only, this is not desired. The change is only fixing boolean widgets, others to come later. Note: It was suggested to use nested inputs, but unfortunately CSS can't traverse (to input) and get back to parent (label), so "for" facility and id must be used. Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65 Bug: https://github.com/mozilla-iot/gateway/issues/1148 Forwarded: https://github.com/mozilla-iot/gateway/pull/1249 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval --- static/js/components/base-component.js | 2 ++ static/js/components/property/boolean.js | 23 +++++++++++----------- static/js/components/property/switch.js | 25 ++++++++++++------------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/static/js/components/base-component.js b/static/js/components/base-component.js index 5cc352e62..40727353b 100644 --- a/static/js/components/base-component.js +++ b/static/js/components/base-component.js @@ -23,6 +23,7 @@ class BaseComponent extends HTMLElement { } this.shadowRoot.appendChild(templateClone); + BaseComponent.count++; } connectedCallback() { @@ -44,4 +45,5 @@ class BaseComponent extends HTMLElement { } } +BaseComponent.count = 0; module.exports = BaseComponent; diff --git a/static/js/components/property/boolean.js b/static/js/components/property/boolean.js index 032c9fce3..deede3b5c 100644 --- a/static/js/components/property/boolean.js +++ b/static/js/components/property/boolean.js @@ -11,8 +11,10 @@ const BaseComponent = require('../base-component'); -const template = document.createElement('template'); -template.innerHTML = ` +class BooleanProperty extends BaseComponent { + constructor() { + const template = document.createElement('template'); + template.innerHTML = `