AngularJS native version of Select2

https://github.com/angular-ui/ui-select

Examples

Bug with required and multiple select

https://github.com/angular-ui/ui-select/issues/914

My solution

'use strict';

/**
* @ngdoc directive
* @name angularApp.directive:uiRequired
*
* @description
* fix for multiple ui-select and required
*
* @example
* <example module="synergyCoreApp">
* <file name="index.html">
* <ui-select ng-model="from" multiple ui-required="true"></ui-select>
* </file>
* </example>
*
*/
angular.module('angularApp')
.directive('uiRequired', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$validators.required = function(modelValue, viewValue) {
return !((viewValue && viewValue.length === 0 || false) &&
attrs.uiRequired === 'true');
};

attrs.$observe('uiRequired', function() {
ctrl.$setValidity('required', !(attrs.uiRequired === 'true' && ctrl.$viewValue && ctrl.$viewValue.length === 0));
});
}
};
});