forms: keep hint as initial option in dynamic <select> (#37301)

This commit is contained in:
Frédéric Péters 2019-11-02 14:43:28 +01:00
parent de68242a59
commit 45554f40b0
1 changed files with 6 additions and 0 deletions

View File

@ -104,7 +104,13 @@ $(function() {
// replace <select> contents
var $select = $widget.find('select');
var current_value = $select.val();
var hint = $widget.find('option[data-hint]').data('hint');
$select.empty();
if (hint) {
var $option = $('<option></option>', {value: '', text: hint});
$option.attr('data-hint', hint);
$option.appendTo($select);
}
for (var i=0; i<value.items.length; i++) {
var $option = $('<option></option>', {value: value.items[i].id, text: value.items[i].text});
if (value.items[i].id == current_value) {