You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 8, 2020. It is now read-only.
Theres a simple_tags option that sets the selected objects id to the model insted of the object itself.
This feature doesn't seem to count with the single select variant of select2. In such case the select2 data() function returns a simple object instead of an array.
Original code:
/*
Convert from Select2 view-model to Angular view-model.
*/
var convertToAngularModel = function(select2_data) {
var model;
if (opts.simple_tags) {
model = [];
angular.forEach(select2_data, function(value, index) {
model.push(value.id);
});
} else {
model = select2_data;
}
return model;
};
/*
Convert from Angular view-model to Select2 view-model.
*/
var convertToSelect2Model = function(angular_data) {
var model = [];
if (!angular_data) {
return model;
}
if (opts.simple_tags) {
model = [];
angular.forEach(
angular_data,
function(value, index) {
model.push({'id': value, 'text': value});
});
} else {
model = angular_data;
}
return model;
};
Possible fix:
/*
Convert from Select2 view-model to Angular view-model.
*/
with the data passed to the callback by initSelection()
var convertToAngularModel = function(select2_data) {
var model;
if (opts.simple_tags) {
if ( elm.data('select2') instanceof window.Select2.class.multi ) { // alternative angular.isArray(select2_data)
/* is multiple */
model = [];
angular.forEach(select2_data, function(value, index) {
model.push(value.id);
});
}
else {
/* is single */
model = select2_data && select2_data.id;
}
} else {
model = select2_data;
}
return model;
};
/*
Convert from Angular view-model to Select2 view-model.
*/
var convertToSelect2Model = function(angular_data) {
var model = [];
if (!angular_data) {
return model;
}
if (opts.simple_tags) {
if ( elm.data('select2') instanceof window.Select2.class.multi ) { // slower alternative angular.isArray(select2_data)
model = [];
angular.forEach(
angular_data,
function(value, index) {
model.push({'id': value, 'text': value});
});
} else {
model = {'id': angular_data, 'text': angular_data};
}
} else {
model = angular_data;
}
return model;
};
I don't know all the features of the select2 jquery plugin so i can't guarantee that this fix will work at all times, but it fixes it for the single option cases.
The text was updated successfully, but these errors were encountered:
Theres a simple_tags option that sets the selected objects id to the model insted of the object itself.
This feature doesn't seem to count with the single select variant of select2. In such case the select2 data() function returns a simple object instead of an array.
Original code:
Possible fix:
I don't know all the features of the select2 jquery plugin so i can't guarantee that this fix will work at all times, but it fixes it for the single option cases.
The text was updated successfully, but these errors were encountered: