Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync classes #27

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions angular-selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
//wait to remove ? to avoid a single select from briefly setting the model to null
selectize.removeOption('?');

syncInputClasses();

var $option = selectize.getOption(0);
if ($option) selectize.setActiveOption($option);
}
Expand All @@ -145,6 +147,7 @@
initializing = false;
element.selectize(opts);
selectize = element[0].selectize;
syncInputClasses();
if (attrs.ngOptions) {
if (scope.multiple) {
selectize.on('item_add', onItemAddMultiSelect);
Expand All @@ -156,6 +159,24 @@
});
}

function syncInputClasses() {
var inputClasses = selectize.$input.attr('class').split(' ');
var controlClasses = selectize.$control.attr('class').split(' ');
var i;

for (i=0; i < controlClasses.length; i++) {
if (controlClasses[i].match(/^ng\-/)) {
selectize.$control.removeClass(controlClasses[i]);
}
}

for (i=0; i < inputClasses.length; i++) {
if (inputClasses[i].match(/^ng\-/)) {
selectize.$control.addClass(inputClasses[i]);
}
}
}

function onItemAddMultiSelect(value, $item) {
var model = ngModelCtrl.$viewValue || [];
var options = optionsFn(scope.$parent);
Expand Down
20 changes: 20 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ describe('<select selectize>', function() {
assert.ok(selectize.$wrapper.hasClass('selectize-control'));
});

it('should copy the angular classes from the <select> into the selectize-input', function () {
var ngClasses = selectize.$wrapper.attr('class').split(' ').filter(function (className) {
return className.match(/^ng\-/);
});

ngClasses.forEach(function (className) {
assert.ok(selectize.$control.hasClass(className));
});
});

it('should have the same number of options in the dropdown menu as DOM options', function() {
assert.strictEqual(selectize.$dropdown_content.children().length, stringOptions.length);
});
Expand Down Expand Up @@ -88,6 +98,16 @@ describe('<select selectize>', function() {
timeout.flush();
testSelectedOption('bar');
});

it('should the selectize-input angular classes', function () {
var ngClasses = selectize.$wrapper.attr('class').split(' ').filter(function (className) {
return className.match(/^ng\-/);
});

ngClasses.forEach(function (className) {
assert.ok(selectize.$control.hasClass(className));
});
});
});
});

Expand Down