Skip to content

Instantly share code, notes, and snippets.

@rnaffer
Created June 6, 2016 16:35
Show Gist options
  • Select an option

  • Save rnaffer/4b42f73814aa7c25a8500f68ad4ddb27 to your computer and use it in GitHub Desktop.

Select an option

Save rnaffer/4b42f73814aa7c25a8500f68ad4ddb27 to your computer and use it in GitHub Desktop.
ui-select Required Directive
app.directive('uiSelectRequired', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$validators.uiSelectRequired = function(modelValue, viewValue) {
for(var prop in modelValue) {
if(modelValue.hasOwnProperty(prop))
return true;
}
return false && JSON.stringify(modelValue) !== JSON.stringify({});
};
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment