Fixing select2 placeholder when the data is reactive
This commit is contained in:
parent
807c288db0
commit
41fb606b2a
@ -19,31 +19,33 @@ OHIF.mixins.select2 = new OHIF.Mixin({
|
|||||||
// Check if this select will include a placeholder
|
// Check if this select will include a placeholder
|
||||||
const placeholder = instance.data.options && instance.data.options.placeholder;
|
const placeholder = instance.data.options && instance.data.options.placeholder;
|
||||||
if (placeholder) {
|
if (placeholder) {
|
||||||
// Get the option items
|
instance.autorun(() => {
|
||||||
let items = instance.data.items;
|
// Get the option items
|
||||||
|
let items = instance.data.items;
|
||||||
|
|
||||||
// Check if the items are reactive and get them if true
|
// Check if the items are reactive and get them if true
|
||||||
const isReactive = items instanceof ReactiveVar;
|
const isReactive = items instanceof ReactiveVar;
|
||||||
if (isReactive) {
|
|
||||||
items = items.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if there is already an empty option on items list
|
|
||||||
if (!_.findWhere(items, { value: '' })) {
|
|
||||||
// Clone the current items
|
|
||||||
const newItems = _.clone(items) || [];
|
|
||||||
newItems.unshift({
|
|
||||||
label: placeholder,
|
|
||||||
value: ''
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set the new items list including the empty option
|
|
||||||
if (isReactive) {
|
if (isReactive) {
|
||||||
instance.data.items.set(newItems);
|
items = items.get();
|
||||||
} else {
|
|
||||||
instance.data.items = newItems;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// Check if there is already an empty option on items list
|
||||||
|
if (!_.findWhere(items, { value: '' })) {
|
||||||
|
// Clone the current items
|
||||||
|
const newItems = _.clone(items) || [];
|
||||||
|
newItems.unshift({
|
||||||
|
label: placeholder,
|
||||||
|
value: ''
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set the new items list including the empty option
|
||||||
|
if (isReactive) {
|
||||||
|
instance.data.items.set(newItems);
|
||||||
|
} else {
|
||||||
|
instance.data.items = newItems;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user