Allowing to get value from select2 before its initialization

This commit is contained in:
Bruno Alves de Faria 2017-07-25 09:50:32 -03:00
parent 927b0c470c
commit 2604e227c0
2 changed files with 19 additions and 1 deletions

View File

@ -179,7 +179,8 @@ OHIF.mixins.schemaData = new OHIF.Mixin({
}
// Fill the component with its default value after rendering
if (currentSchema.defaultValue) {
if (!_.isUndefined(currentSchema.defaultValue)) {
component.defaultValue = currentSchema.defaultValue;
component.value(currentSchema.defaultValue);
}
}

View File

@ -15,9 +15,23 @@ OHIF.mixins.select2 = new OHIF.Mixin({
const instance = Template.instance();
const { component, data } = instance;
// Controls select2 initialization
instance.isInitialized = false;
// Set the custom focus flag
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
instance.getDropdownContainerElement = () => {
const $select2 = component.$element.nextAll('.select2:first');
@ -113,6 +127,9 @@ OHIF.mixins.select2 = new OHIF.Mixin({
instance.component.$element.focus();
}
});
// Set select2 as initialized
instance.isInitialized = true;
};
instance.autorun(() => {