From ab3fbd56bdb7e2545cd02c653aaa9083fe99af60 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Thu, 4 Jul 2013 20:42:21 +0000 Subject: [PATCH] Promote label attribute from inputWidget to parent valueWidget, fixes missing labels on some readonly widgets --- etemplate/js/et2_core_inputWidget.js | 64 ---------------------------- etemplate/js/et2_core_valueWidget.js | 58 ++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 65 deletions(-) diff --git a/etemplate/js/et2_core_inputWidget.js b/etemplate/js/et2_core_inputWidget.js index 9babe580c0..d746a569c6 100644 --- a/etemplate/js/et2_core_inputWidget.js +++ b/etemplate/js/et2_core_inputWidget.js @@ -34,13 +34,6 @@ var et2_inputWidget = et2_valueWidget.extend([et2_IInput,et2_ISubmitListener], "type": "boolean", "description": "If required, the user must enter a value before the form can be submitted" }, - "label": { - "name": "Label", - "default": "", - "type": "string", - "description": "The label is displayed by default in front (for radiobuttons behind) each widget (if not empty). If you want to specify a different position, use a '%s' in the label, which gets replaced by the widget itself. Eg. '%s Name' to have the label Name behind a checkbox. The label can contain variables, as descript for name. If the label starts with a '@' it is replaced by the value of the content-array at this index (with the '@'-removed and after expanding the variables).", - "translate": true - }, "onchange": { "name": "onchange", "type": "string", @@ -168,63 +161,6 @@ var et2_inputWidget = et2_valueWidget.extend([et2_IInput,et2_ISubmitListener], } }, - set_label: function(_value) { - // Abort if ther was no change in the label - if (_value == this.label) - { - return; - } - - if (_value) - { - // Create the label container if it didn't exist yet - if (this._labelContainer == null) - { - this._labelContainer = $j(document.createElement("label")) - .addClass("et2_label"); - this.getSurroundings().insertDOMNode(this._labelContainer[0]); - } - - // Clear the label container. - this._labelContainer.empty(); - - // Create the placeholder element and set it - var ph = document.createElement("span"); - this.getSurroundings().setWidgetPlaceholder(ph); - - // Split the label at the "%s" - var parts = et2_csvSplit(_value, 2, "%s"); - - // Update the content of the label container - for (var i = 0; i < parts.length; i++) - { - if (parts[i]) - { - this._labelContainer.append(document.createTextNode(parts[i])); - } - if (i == 0) - { - this._labelContainer.append(ph); - } - } - } - else - { - // Delete the labelContainer from the surroundings object - if (this._labelContainer) - { - this.getSurroundings().removeDOMNode(this._labelContainer[0]); - } - this._labelContainer = null; - } - - // Update the surroundings in order to reflect the change in the label - this.getSurroundings().update(); - - // Copy the given value - this.label = _value; - }, - set_needed: function(_value) { var node = this.getInputNode(); if (node) diff --git a/etemplate/js/et2_core_valueWidget.js b/etemplate/js/et2_core_valueWidget.js index 6158f966b2..7c84cbf404 100644 --- a/etemplate/js/et2_core_valueWidget.js +++ b/etemplate/js/et2_core_valueWidget.js @@ -69,7 +69,63 @@ var et2_valueWidget = et2_baseWidget.extend( } } - } + }, + set_label: function(_value) { + // Abort if ther was no change in the label + if (_value == this.label) + { + return; + } + + if (_value) + { + // Create the label container if it didn't exist yet + if (this._labelContainer == null) + { + this._labelContainer = $j(document.createElement("label")) + .addClass("et2_label"); + this.getSurroundings().insertDOMNode(this._labelContainer[0]); + } + + // Clear the label container. + this._labelContainer.empty(); + + // Create the placeholder element and set it + var ph = document.createElement("span"); + this.getSurroundings().setWidgetPlaceholder(ph); + + // Split the label at the "%s" + var parts = et2_csvSplit(_value, 2, "%s"); + + // Update the content of the label container + for (var i = 0; i < parts.length; i++) + { + if (parts[i]) + { + this._labelContainer.append(document.createTextNode(parts[i])); + } + if (i == 0) + { + this._labelContainer.append(ph); + } + } + } + else + { + // Delete the labelContainer from the surroundings object + if (this._labelContainer) + { + this.getSurroundings().removeDOMNode(this._labelContainer[0]); + } + this._labelContainer = null; + } + + // Update the surroundings in order to reflect the change in the label + this.getSurroundings().update(); + + // Copy the given value + this.label = _value; + } });