Allowing to get value from select2 before its initialization
This commit is contained in:
parent
927b0c470c
commit
2604e227c0
@ -179,7 +179,8 @@ OHIF.mixins.schemaData = new OHIF.Mixin({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fill the component with its default value after rendering
|
// Fill the component with its default value after rendering
|
||||||
if (currentSchema.defaultValue) {
|
if (!_.isUndefined(currentSchema.defaultValue)) {
|
||||||
|
component.defaultValue = currentSchema.defaultValue;
|
||||||
component.value(currentSchema.defaultValue);
|
component.value(currentSchema.defaultValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,9 +15,23 @@ OHIF.mixins.select2 = new OHIF.Mixin({
|
|||||||
const instance = Template.instance();
|
const instance = Template.instance();
|
||||||
const { component, data } = instance;
|
const { component, data } = instance;
|
||||||
|
|
||||||
|
// Controls select2 initialization
|
||||||
|
instance.isInitialized = false;
|
||||||
|
|
||||||
// Set the custom focus flag
|
// Set the custom focus flag
|
||||||
component.isCustomFocus = true;
|
component.isCustomFocus = true;
|
||||||
|
|
||||||
|
const valueMethod = component.value;
|
||||||
|
component.value = value => {
|
||||||
|
if (_.isUndefined(value) && !instance.isInitialized) {
|
||||||
|
if (!_.isUndefined(instance.data.value)) return instance.data.value;
|
||||||
|
if (!_.isUndefined(component.defaultValue)) return component.defaultValue;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return valueMethod(value);
|
||||||
|
};
|
||||||
|
|
||||||
// Utility function to get the dropdown jQuery element
|
// Utility function to get the dropdown jQuery element
|
||||||
instance.getDropdownContainerElement = () => {
|
instance.getDropdownContainerElement = () => {
|
||||||
const $select2 = component.$element.nextAll('.select2:first');
|
const $select2 = component.$element.nextAll('.select2:first');
|
||||||
@ -113,6 +127,9 @@ OHIF.mixins.select2 = new OHIF.Mixin({
|
|||||||
instance.component.$element.focus();
|
instance.component.$element.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Set select2 as initialized
|
||||||
|
instance.isInitialized = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
instance.autorun(() => {
|
instance.autorun(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user