Skip to content

Commit 04675a6

Browse files
committed
Handle situation where datalist is associated with more than one input.
1 parent 0ef1703 commit 04675a6

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

js/jquery.relevant-dropdown.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,31 @@
2929
temp_items = document.createDocumentFragment(),
3030
temp_item = null;
3131

32-
// Insert home for new fake datalist
33-
$("<ul />", {
34-
"class": "datalist",
35-
"id" : list_id
36-
}).appendTo("body");
37-
38-
// Remove old datalist
39-
$datalist.remove();
40-
41-
// Update pointer
42-
$datalist = $("#" + list_id);
43-
44-
// Fill new fake datalist
45-
datalistItems.each(function() {
46-
temp_item = $("<li />", {
47-
// .val is required here, not .text or .html
48-
// HTML *needs* to be <option value="xxx"> not <option>xxx</option> (IE)
49-
"text": $(this).val()
50-
})[0];
51-
temp_items.appendChild(temp_item);
52-
});
53-
$datalist.append(temp_items);
32+
// make sure we haven't already converted the datalist
33+
if (!$("ul#" + list_id).is($datalist)) {
34+
// Insert home for new fake datalist
35+
$("<ul />", {
36+
"class": "datalist",
37+
"id" : list_id
38+
}).appendTo("body");
39+
40+
// Remove old datalist
41+
$datalist.remove();
42+
43+
// Update pointer
44+
$datalist = $("#" + list_id);
45+
46+
// Fill new fake datalist
47+
datalistItems.each(function() {
48+
temp_item = $("<li />", {
49+
// .val is required here, not .text or .html
50+
// HTML *needs* to be <option value="xxx"> not <option>xxx</option> (IE)
51+
"text": $(this).val()
52+
})[0];
53+
temp_items.appendChild(temp_item);
54+
});
55+
$datalist.append(temp_items);
56+
}
5457

5558
// Update pointer
5659
datalistItems = $datalist.find("li");

0 commit comments

Comments
 (0)