make sure to remove label tag from DOM if label is updated to NULL

This commit is contained in:
Carson Sievert
2019-04-26 19:08:15 -05:00
parent 938332d646
commit 5e8bc204c1
5 changed files with 34 additions and 15 deletions

View File

@@ -4326,15 +4326,23 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
receiveMessage: function receiveMessage(el, data) {
if (data.hasOwnProperty('value')) this.setValue(el, data.value);
var labelTag = $(el).parent().find('label[for="' + $escape(el.id) + '"]');
var hasLabelTag = labelTag.length > 0;
// If data.label exists, then we may need to insert a label
// tag into the DOM. If it doesn't exist, then the label tag
// should be removed to be more consistent with the behavior
// of `textInput(label = NULL)`
if (data.hasOwnProperty('label')) {
var label = $(el).parent().find('label[for="' + $escape(el.id) + '"]');
// If textInput(label=NULL), then no label tag is provided from the
// server, so create one if we need to.
if (label.length === 0) {
$('<label for="' + $escape(el.id) + '">' + data.label + '</label>').insertBefore(el);
if (hasLabelTag) {
labelTag.text(data.label);
} else {
label.text(data.label);
$('<label for="' + $escape(el.id) + '">' + data.label + '</label>').insertBefore(el);
}
} else {
if (hasLabelTag) labelTag.remove();
}
if (data.hasOwnProperty('placeholder')) el.placeholder = data.placeholder;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long