CRM.loadForm($(this).attr('href'), {
dialog: {width: 500, height: 'auto'}
}).on('crmFormSuccess', function(e, data) {
- if ($el.select2('container').hasClass('select2-container-multi')) {
- var selection = $el.select2('data');
- selection.push(data);
- $el.select2('data', selection);
- } else {
- $el.select2('data', data);
+ if (data.status === 'success' && data.id) {
+ if ($el.select2('container').hasClass('select2-container-multi')) {
+ var selection = $el.select2('data');
+ selection.push(data);
+ $el.select2('data', selection, true);
+ } else {
+ $el.select2('data', data, true);
+ }
}
});
return false;