Have textInput()'s receiveMessage method insert a label tag if one is needed, closes #868

This commit is contained in:
Carson Sievert
2019-04-26 16:56:53 -05:00
parent 386078d441
commit 938332d646
5 changed files with 35 additions and 18 deletions

View File

@@ -27,8 +27,16 @@ $.extend(textInputBinding, {
if (data.hasOwnProperty('value'))
this.setValue(el, data.value);
if (data.hasOwnProperty('label'))
$(el).parent().find('label[for="' + $escape(el.id) + '"]').text(data.label);
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);
} else {
label.text(data.label);
}
}
if (data.hasOwnProperty('placeholder'))
el.placeholder = data.placeholder;