From b5024a063d560110064913a02e5419a86d11eba2 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Mon, 13 Mar 2017 18:07:29 +0100 Subject: [PATCH] Fixed issue with dynamic checkboxes --- resource/web/event_config.tmpl | 15 +++++++++++---- resource/web/sensor_config.tmpl | 15 +++++++++++---- resource/web/trigger.tmpl | 14 +++++++++++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/resource/web/event_config.tmpl b/resource/web/event_config.tmpl index 10476b75..b73df495 100755 --- a/resource/web/event_config.tmpl +++ b/resource/web/event_config.tmpl @@ -118,10 +118,17 @@ $.each(button.attr(), function(fieldName, value) { if(fieldName.startsWith("data-")) { fieldName = fieldName.substring(5); - // case insensitive search - modal.find("input").filter(function() { + input = modal.find("input").filter(function() { return this.name.toLowerCase() == fieldName; - }).val(value); + }); + if (input.attr("type") == "checkbox") { // special handling for checkboxes + if (value=="true") input.attr("checked", "true"); + else input.removeAttr("checked", "true"); + // Add default false value as a unchecked checkbox is not included in the post + input.parent().prepend(""); + } else { + input.val(value); + } } }); }); @@ -174,7 +181,7 @@ {{#.isTypeString()}}{{/#.isTypeString()}} {{#.isTypeInt()}}{{/#.isTypeInt()}} - {{#.isTypeBoolean()}}{{/#.isTypeBoolean()}} + {{#.isTypeBoolean()}}{{/#.isTypeBoolean()}} {{#.isTypeEnum()}} "); + } else { + input.val(value); + } } }); }); @@ -306,7 +313,7 @@ {{#.isTypeString()}}{{/#.isTypeString()}} {{#.isTypeInt()}}{{/#.isTypeInt()}} - {{#.isTypeBoolean()}}{{/#.isTypeBoolean()}} + {{#.isTypeBoolean()}}{{/#.isTypeBoolean()}} {{#.isTypeEnum()}} "); + } else { + input.val(value); + } } }); }); @@ -280,7 +288,7 @@ {{#.isTypeString()}}{{/#.isTypeString()}} {{#.isTypeInt()}}{{/#.isTypeInt()}} - {{#.isTypeBoolean()}}{{/#.isTypeBoolean()}} + {{#.isTypeBoolean()}}{{/#.isTypeBoolean()}} {{#.isTypeEnum()}}