-
Notifications
You must be signed in to change notification settings - Fork 540
Feature request: add support for ng-required #157
Comments
I'm not sure whether supporting a <tags-input ng-model="tags" min-tags="2" ng-required="required"></tags-input> <tags-input ng-model="tags" min-tags="0" ng-required="required"></tags-input> In the first example, the value of I don't think the extra code to handle these situations is worth it since |
Uhh, min-tags is not an expression, am I right? That means I can't change it run-time, which is what we would like to do. |
I think we're conflating the purpose of these two tickets. This one is only for In my opinion, the code to support checking if (options.ngRequired && options.minTags < 1) {
options.minTags = 1;
} This way, it only changes the logic if the |
Well, here is my workaround. This is probably ugly, but whatever, this works for me.
scope: {
tags: '=ngModel',
onTagAdded: '&',
onTagRemoved: '&', // don't forget the comma
ngRequired: '=' // new
},
scope.$watch('tags.length', function(value) {
ngModelCtrl.$setValidity('maxTags', angular.isUndefined(options.maxTags) || value <= options.maxTags);
ngModelCtrl.$setValidity('minTags', angular.isUndefined(options.minTags) || value >= options.minTags);
}); and change it to this: var isRequired = false;
var setValidity = function (length) {
ngModelCtrl.$setValidity('maxTags', angular.isUndefined(options.maxTags) || length <= options.maxTags);
ngModelCtrl.$setValidity('minTags', angular.isUndefined(options.minTags) || length >= options.minTags || !isRequired);
};
scope.$watch('ngRequired', function (required) {
isRequired = required;
setValidity(scope.tags.length);
});
scope.$watch('tags.length', function (length) {
setValidity(length);
}); Usage: <tags-input ng-model="BINDING" min-tags="1" ng-required="EXPRESSION">
</tags-input> This way if ng-required is false - min-tags is ignored. |
+1 |
@geoffstokes Don't worry. I'm aware of the differences between issue #154 and this one. @igoreso All options, including About |
Add support for the ng-required directive so the required validation key is set when there are no tags in the model bound to the tagsInput directive. Closes mbenford#157
The following Plunk originally posted by @geoffstokes in issue #154 fits nicely for this feature.
http://plnkr.co/edit/u6eh1ISksdFUpoInafij?p=preview
The text was updated successfully, but these errors were encountered: