From be6325a68c458c53a0c2c94c11e37b4f019d577c Mon Sep 17 00:00:00 2001 From: nathangray Date: Tue, 13 Aug 2019 13:28:56 -0600 Subject: [PATCH] Etemplate - fully implement label widget's "for" attribute --- api/js/etemplate/et2_widget_description.js | 36 +++++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/api/js/etemplate/et2_widget_description.js b/api/js/etemplate/et2_widget_description.js index 07db9b469a..b2ded1fa79 100644 --- a/api/js/etemplate/et2_widget_description.js +++ b/api/js/etemplate/et2_widget_description.js @@ -118,11 +118,7 @@ var et2_description = (function(){ "use strict"; return expose(et2_baseWidget.ex this.span = jQuery(document.createElement(this.options["for"] ? "label" : "span")) .addClass("et2_label"); - if (this.options["for"]) - { - // TODO: Get the real id of the widget in the doLoadingFinished method. - this.span.attr("for", this.options["for"]); - } + et2_insertLinkText(this._parseText(this.options.value), this.span[0], this.options.href ? this.options.extra_link_target : '_blank'); @@ -144,6 +140,36 @@ var et2_description = (function(){ "use strict"; return expose(et2_baseWidget.ex } }, + doLoadingFinished: function() { + + this._super.apply(this, arguments); + + // Get the real id of the 'for' widget + var for_widget = null; + if (this.options["for"] && ( + (for_widget = this.getParent().getWidgetById(this.options.for)) || + (for_widget = this.getRoot().getWidgetById(this.options.for)) + ) && for_widget && for_widget.id) + { + if(for_widget.dom_id) + { + this.span.attr("for", for_widget.dom_id); + } + else + { + // Target widget is not done yet, need to wait + var tab_deferred = jQuery.Deferred(); + window.setTimeout(function() { + this.span.attr("for", for_widget.dom_id); + tab_deferred.resolve(); + }.bind(this),0); + + return tab_deferred.promise(); + } + } + return true; + }, + set_label: function(_value) { // Abort if ther was no change in the label if (_value == this.label)