Skip to content

Commit

Permalink
contentpicker: Don't validate minNumber/maxNumber if 0
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-shuy authored and bergmania committed Nov 16, 2021
1 parent af942b2 commit e2fdf43
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ function contentPickerController($scope, $q, $routeParams, $location, entityReso
if ($scope.contentPickerForm) {
//Validate!
var hasItemsOrMandatory = $scope.renderModel.length !== 0 || ($scope.model.validation && $scope.model.validation.mandatory);
if (hasItemsOrMandatory && $scope.minNumberOfItems > $scope.renderModel.length) {
if (hasItemsOrMandatory && $scope.minNumberOfItems && $scope.minNumberOfItems > $scope.renderModel.length) {
$scope.contentPickerForm.minCount.$setValidity("minCount", false);
}
else {
$scope.contentPickerForm.minCount.$setValidity("minCount", true);
}

if ($scope.maxNumberOfItems < $scope.renderModel.length) {
if ($scope.maxNumberOfItems && $scope.maxNumberOfItems < $scope.renderModel.length) {
$scope.contentPickerForm.maxCount.$setValidity("maxCount", false);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
<div class="umb-contentpicker__min-max-help" ng-if="model.config.multiPicker === true && (maxNumberOfItems > 1 || minNumberOfItems > 0) && (renderModel.length !== 0 || (model.validation && model.validation.mandatory))">

<!-- Both min and max items -->
<span ng-if="minNumberOfItems !== maxNumberOfItems">
<span ng-if="minNumberOfItems && maxNumberOfItems && minNumberOfItems !== maxNumberOfItems">
<span ng-if="renderModel.length < maxNumberOfItems">Add between {{minNumberOfItems}} and {{maxNumberOfItems}} items</span>
<span ng-if="renderModel.length > maxNumberOfItems">
<localize key="validation_maxCount">You can only have</localize> {{maxNumberOfItems}} <localize key="validation_itemsSelected"> items selected</localize>
</span>
</span>

<!-- Equal min and max -->
<span ng-if="minNumberOfItems === maxNumberOfItems">
<span ng-if="minNumberOfItems && maxNumberOfItems && minNumberOfItems === maxNumberOfItems">
<span ng-if="renderModel.length < maxNumberOfItems">Add {{minNumberOfItems - renderModel.length}} item(s)</span>
<span ng-if="renderModel.length > maxNumberOfItems">
<localize key="validation_maxCount">You can only have</localize> {{maxNumberOfItems}} <localize key="validation_itemsSelected"> items selected</localize>
Expand Down

0 comments on commit e2fdf43

Please sign in to comment.