V8/feature/5914 broken backoffice validation (#6989)

* validate max length for textbox

* validate max length for textarea
This commit is contained in:
Rasmus Østergård
2019-12-20 08:35:24 +01:00
committed by Kenn Jacobsen
parent e578ca1b0f
commit 9c33ebc98a
4 changed files with 31 additions and 4 deletions

View File

@@ -15,7 +15,22 @@ function textAreaController($scope, validationMessageService) {
if ($scope.model.config && $scope.model.config.maxChars) {
$scope.model.maxlength = true;
}
$scope.$on("formSubmitting", function() {
if ($scope.isLengthValid()) {
$scope.textareaFieldForm.textarea.$setValidity("maxChars", true);
} else {
$scope.textareaFieldForm.textarea.$setValidity("maxChars", false);
}
});
$scope.isLengthValid = function() {
if (!$scope.model.maxlength) {
return true;
}
return $scope.model.config.maxChars >= $scope.model.count;
}
$scope.model.change = function () {
if ($scope.model.value) {
$scope.model.count = $scope.model.value.length;

View File

@@ -10,7 +10,7 @@
<div class="help" ng-if="model.maxlength === true && model.count >= (model.config.maxChars*.8) && model.count <= model.config.maxChars">
<localize key="textbox_characters_left" tokens="[model.config.maxChars - model.count]" watch-tokens="true">%0% characters left.</localize>
</div>
<div class="help text-error" ng-if="model.maxlength === true && model.count > model.config.maxChars">
<div class="help text-error" ng-if="!isLengthValid()">
<localize key="textbox_characters_exceed" tokens="[model.config.maxChars, model.count - model.config.maxChars]" watch-tokens="true">Maximum %0% characters, <strong>%1%</strong> too many.</localize>
</div>

View File

@@ -11,7 +11,19 @@ function textboxController($scope, validationMessageService) {
// if no max is specified in the config
$scope.model.config.maxChars = 500;
}
$scope.$on("formSubmitting", function() {
if ($scope.isLengthValid()) {
$scope.textboxFieldForm.textbox.$setValidity("maxChars", true);
} else {
$scope.textboxFieldForm.textbox.$setValidity("maxChars", false);
}
});
$scope.isLengthValid = function() {
return $scope.model.config.maxChars >= $scope.model.count;
}
$scope.model.change = function () {
if ($scope.model.value) {
$scope.model.count = $scope.model.value.length;

View File

@@ -19,7 +19,7 @@
<p class="sr-only" tabindex="0">{{model.label}} <localize key="textbox_characters_left" tokens="[model.config.maxChars - model.count]" watch-tokens="true">%0% characters left.</localize></p>
<p aria-hidden="True"><localize key="textbox_characters_left" tokens="[model.config.maxChars - model.count]" watch-tokens="true">%0% characters left.</localize></p>
</div>
<div class="help text-error" ng-if="model.count > model.config.maxChars">
<div class="help text-error" ng-if="!isLengthValid()">
<p class="sr-only" tabindex="0">{{model.label}} <localize key="textbox_characters_exceed" tokens="[model.config.maxChars, model.count - model.config.maxChars]" watch-tokens="true">Maximum %0% characters, <strong>%1%</strong> too many.</localize></p>
<p aria-hidden="true"><localize key="textbox_characters_exceed" tokens="[model.config.maxChars, model.count - model.config.maxChars]" watch-tokens="true">Maximum %0% characters, <strong>%1%</strong> too many.</localize></p>
</div>