From 9a482e43c71b19c863654cc50a9dd22b25e1f1a0 Mon Sep 17 00:00:00 2001 From: Philippe Coval Date: Thu, 2 Aug 2018 10:38:07 +0200 Subject: [PATCH] ui: Allow multiple same properties in single thing Previously item ids were duplicated, the observed consequence is that any click on widgets is seen as click on 1st declared element. For example, a thing with 2 switches is displayed correctly, and click events are also triggered but will be "redirected" to 1st switch only, this is not desired. Change-Id: I27ef75a95889c37224aa7da6b0fbf8e2ad57ba65 Bug: https://github.com/mozilla-iot/gateway/issues/1148 Origin: https://github.com/tizenteam/gateway Signed-off-by: Philippe Coval --- static/js/components/base-component.js | 2 ++ static/js/components/property/boolean.js | 16 +++++++++------- static/js/components/property/switch.js | 16 +++++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/static/js/components/base-component.js b/static/js/components/base-component.js index 2096a80f85..4d5fa65e8a 100644 --- a/static/js/components/base-component.js +++ b/static/js/components/base-component.js @@ -12,6 +12,7 @@ class BaseComponent extends HTMLElement { constructor(template) { super(); + const idSuffix = ++(BaseComponent.count); this.attachShadow({mode: 'open'}); this.shadowRoot.appendChild(template.content.cloneNode(true)); } @@ -35,4 +36,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 032c9fce38..79030102e1 100644 --- a/static/js/components/property/boolean.js +++ b/static/js/components/property/boolean.js @@ -11,8 +11,12 @@ const BaseComponent = require('../base-component'); -const template = document.createElement('template'); -template.innerHTML = ` +class BooleanProperty extends BaseComponent { + constructor() { + const element = 'checkbox'; + const id=`${element}${BaseComponent.count}`; + var template = document.createElement('template'); + template.innerHTML = `