Commit c0bb8bd4 authored by Debarshi Bhaumik's avatar Debarshi Bhaumik

Fix select2 value updation for crmAddName Directive

parent dcea8651
......@@ -103,7 +103,9 @@
};
$(input).crmSelect2({
data: scope[attrs.crmOptions],
data: function () {
return { results: scope[attrs.crmOptions] };
},
createSearchChoice: function(term) {
return {id: term, text: term + ' (' + ts('new') + ')'};
},
......@@ -116,11 +118,6 @@
scope.$evalAsync('_resetSelection()');
e.preventDefault();
});
scope.$watch(attrs.crmOptions, function(value) {
$(input).select2('data', scope[attrs.crmOptions]);
$(input).select2('val', '');
});
}
};
});
......
......@@ -253,6 +253,34 @@ describe('crmCaseType', function() {
expect(newSet.timeline).toBe('1');
expect(newSet.label).toBe('Timeline #2');
});
});
describe('crmAddName', function () {
var scope;
var element;
beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new();
scope.activityTypeOptions = [1, 2, 3];
element = '<span crm-add-name crm-options="activityTypeOptions"></span>';
spyOn(CRM.$.fn, 'crmSelect2').and.callThrough();
element = $compile(element)(scope);
scope.$digest();
}));
describe('when initialized', function () {
var returnValue;
beforeEach (function () {
var dataFunction = CRM.$.fn.crmSelect2.calls.argsFor(0)[0].data;
returnValue = dataFunction();
});
it('updates the UI with updated value of scope variable', function () {
expect(returnValue).toEqual({ results: scope.activityTypeOptions });
});
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment