Inputs now always supply a <label> tag with a special CSS class for hiding NULL labels

This helps to simplify the updating logic on the client
This commit is contained in:
Carson Sievert
2019-05-03 15:38:57 -05:00
parent 34ee48ef93
commit 370f1b51ee
25 changed files with 134 additions and 141 deletions

View File

@@ -40,7 +40,7 @@ $.extend(selectInputBinding, {
}
return {
label: $(el).parent().find('label[for="' + $escape(el.id) + '"]').text(),
label: this._getLabelNode(el),
value: this.getValue(el),
options: options
};
@@ -123,14 +123,7 @@ $.extend(selectInputBinding, {
this.setValue(el, data.value);
}
let escaped_id = $escape(el.id);
if (this._is_selectize(el)) {
escaped_id += "-selectized";
}
var labelNode = $(el).parent().parent()
.find('label[for="' + escaped_id + '"]');
var labelHTML = "<label for='" + escaped_id + "'></label>";
updateLabel(data.label, labelNode, labelHTML, el);
updateLabel(data.label, this._getLabelNode(el));
$(el).trigger('change');
},
@@ -151,6 +144,13 @@ $.extend(selectInputBinding, {
initialize: function(el) {
this._selectize(el);
},
_getLabelNode: function(el) {
let escaped_id = $escape(el.id);
if (this._is_selectize(el)) {
escaped_id += "-selectized";
}
return $(el).parent().parent().find('label[for="' + escaped_id + '"]');
},
// Return true if it's a selectize input, false if it's a regular select input.
_is_selectize: function(el) {
var config = $(el).parent().find('script[data-for="' + $escape(el.id) + '"]');