From 6f2c99ae3ecf78188a46927d7ee10ac7268527ce Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 11 Apr 2017 15:49:57 +0400 Subject: [PATCH] automatically update dropdown label when setting items --- plugins/c9.ide.ui/forms.js | 11 ++--------- plugins/c9.ide.ui/lib/dropdown.js | 10 +++------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/plugins/c9.ide.ui/forms.js b/plugins/c9.ide.ui/forms.js index 6d32005f..2e656092 100644 --- a/plugins/c9.ide.ui/forms.js +++ b/plugins/c9.ide.ui/forms.js @@ -203,9 +203,7 @@ define(function(require, exports, module) { value: options.path ? settings.get(options.path) : (options.defaultValue || ""), - // each: options.each || "item", caption: options.caption, - // eachvalue: options.eachvalue || "value", "empty-message": options["empty-message"] }) ]; @@ -458,16 +456,11 @@ define(function(require, exports, module) { case "dropdown": var dropdown = el.lastChild; - if (item.items) { + if (item.items) dropdown.setChildren(item.items); - var value = item.value || dropdown.value; - dropdown.value = -999; - dropdown.setAttribute("value", value); - } - else if (item.value) { + if (item.value != null) dropdown.setAttribute("value", item.value); - } break; default: // supported attributes diff --git a/plugins/c9.ide.ui/lib/dropdown.js b/plugins/c9.ide.ui/lib/dropdown.js index 721d5a3f..6b022f28 100644 --- a/plugins/c9.ide.ui/lib/dropdown.js +++ b/plugins/c9.ide.ui/lib/dropdown.js @@ -328,6 +328,7 @@ apf.dropdown = function(struct, tagName) { return; } } + this.$setLabel(String(value)); }; function isValueEqual(v1, v2) { @@ -469,7 +470,6 @@ apf.dropdown = function(struct, tagName) { this.$setLabel = function(value) { this.oLabel.innerHTML = value || this["initial-message"] || ""; - this.$setStyleClass(this.$ext, value ? "" : this.$baseCSSname + "Initial", !value ? [] : [this.$baseCSSname + "Initial"]); }; @@ -477,17 +477,12 @@ apf.dropdown = function(struct, tagName) { // Private functions this.$blur = function() { this.slideUp(); - //this.$ext.dispatchEvent("mouseout") if (!this.isOpen) - this.$setStyleClass(this.$ext, "", [this.$baseCSSname + "Over"]) + this.$setStyleClass(this.$ext, "", [this.$baseCSSname + "Over"]); this.$setStyleClass(this.$ext, "", [this.$baseCSSname + "Focus"]); }; - /*this.$focus = function(){ - apf.popup.forceHide(); - this.$setStyleClass(this.oFocus || this.$ext, this.$baseCSSname + "Focus"); - }*/ this.$setClearMessage = function(msg) { this.$setLabel(msg); @@ -504,6 +499,7 @@ apf.dropdown = function(struct, tagName) { this.items = data; if (this.isOpen) this.$updateChildren(); + this.$propHandlers["value"].call(this, this.value); }; this.change =