Merge pull request #7662 from nathanwoulfe/7647-clear-validation-after-clearing-property
v8: 7647 Can't save content after clearing property with validation error
This commit is contained in:
@@ -26,7 +26,6 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
//create properties on our custom scope so we can use it in our template
|
||||
scope.errorMsg = "";
|
||||
|
||||
|
||||
//the property form controller api
|
||||
var formCtrl = ctrl[0];
|
||||
//the valFormManager controller api
|
||||
@@ -38,7 +37,9 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
|
||||
var currentProperty = umbPropCtrl.property;
|
||||
scope.currentProperty = currentProperty;
|
||||
|
||||
var currentCulture = currentProperty.culture;
|
||||
var isMandatory = currentProperty.validation.mandatory;
|
||||
|
||||
var labels = {};
|
||||
localizationService.localize("errors_propertyHasErrors").then(function (data) {
|
||||
@@ -91,12 +92,12 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
if (!watcher) {
|
||||
watcher = scope.$watch("currentProperty.value",
|
||||
function (newValue, oldValue) {
|
||||
|
||||
if (angular.equals(newValue, oldValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var errCount = 0;
|
||||
|
||||
for (var e in formCtrl.$error) {
|
||||
if (angular.isArray(formCtrl.$error[e])) {
|
||||
errCount++;
|
||||
@@ -107,7 +108,9 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
// based on other errors. We'll also check if there's no other validation errors apart from valPropertyMsg, if valPropertyMsg
|
||||
// is the only one, then we'll clear.
|
||||
|
||||
if (errCount === 0 || (errCount === 1 && angular.isArray(formCtrl.$error.valPropertyMsg)) || (formCtrl.$invalid && angular.isArray(formCtrl.$error.valServer))) {
|
||||
if (errCount === 0
|
||||
|| (errCount === 1 && angular.isArray(formCtrl.$error.valPropertyMsg))
|
||||
|| (formCtrl.$invalid && angular.isArray(formCtrl.$error.valServer))) {
|
||||
scope.errorMsg = "";
|
||||
formCtrl.$setValidity('valPropertyMsg', true);
|
||||
} else if (showValidation && scope.errorMsg === "") {
|
||||
@@ -136,6 +139,21 @@ function valPropertyMsg(serverValidationManager, localizationService) {
|
||||
}
|
||||
//if there are any errors in the current property form that are not valPropertyMsg
|
||||
else if (_.without(_.keys(formCtrl.$error), "valPropertyMsg").length > 0) {
|
||||
|
||||
// errors exist, but if the property is NOT mandatory and has no value, the errors should be cleared
|
||||
if (!isMandatory && !currentProperty.value) {
|
||||
hasError = false;
|
||||
showValidation = false;
|
||||
scope.errorMsg = "";
|
||||
|
||||
// if there's no value, the controls can be reset, which clears the error state on formCtrl
|
||||
for (let control of formCtrl.$getControls()) {
|
||||
control.$setValidity();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
hasError = true;
|
||||
//update the validation message if we don't already have one assigned.
|
||||
if (showValidation && scope.errorMsg === "") {
|
||||
|
||||
Reference in New Issue
Block a user