take valserver and valpropertymsg out of business if we are dealing with invariant property on non-default-language

This commit is contained in:
Niels Lyngsø
2019-04-11 13:03:28 +02:00
parent 760b7ad0ce
commit 92a0ec2964
2 changed files with 32 additions and 18 deletions

View File

@@ -12,27 +12,45 @@
function valPropertyMsg(serverValidationManager) {
return {
require: ['^^form', '^^valFormManager', '^^umbProperty'],
require: ['^^form', '^^valFormManager', '^^umbProperty', '?^^umbVariantContent'],
replace: true,
restrict: "E",
template: "<div ng-show=\"errorMsg != ''\" class='alert alert-error property-error' >{{errorMsg}}</div>",
scope: {},
link: function (scope, element, attrs, ctrl) {
var unsubscribe = [];
var watcher = null;
var hasError = false;
//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
var valFormManager = ctrl[1];
//the property controller api
var umbPropCtrl = ctrl[2];
//the variants controller api
var umbVariantCtrl = ctrl[3];
var currentProperty = umbPropCtrl.property;
scope.currentProperty = currentProperty;
var currentCulture = currentProperty.culture;
var currentVariant = umbVariantCtrl.editor.content;
// Lets check if we have variants and we are on the default language then ...
if(umbVariantCtrl && umbVariantCtrl.content.variants.length > 1 && !currentVariant.language.isDefault && !currentCulture && !currentProperty.unlockInvariantValue) {
//This property is locked cause its a invariant property shown on a non-default language.
//Therefor do not validate this field.
return;
}
// if we have reached this part, and there is no culture, then lets fallback to invariant. To get the validation feedback for invariant language.
currentCulture = currentCulture || "invariant";
scope.currentProperty = umbPropCtrl.property;
//if the property is invariant (no culture), then we will explicitly set it to the string 'invariant'
//since this matches the value that the server will return for an invariant property.
var currentCulture = scope.currentProperty.culture || "invariant";
var watcher = null;
// Gets the error message to display
function getErrorMsg() {
@@ -138,13 +156,6 @@ function valPropertyMsg(serverValidationManager) {
}
var hasError = false;
//create properties on our custom scope so we can use it in our template
scope.errorMsg = "";
var unsubscribe = [];
//listen for form validation changes.
//The alternative is to add a watch to formCtrl.$invalid but that would lead to many more watches then
// subscribing to this single watch.

View File

@@ -24,15 +24,18 @@ function valServer(serverValidationManager) {
var currentProperty = umbPropCtrl.property;
var currentCulture = currentProperty.culture;
var currentVariant = umbVariantCtrl.editor.content;
var currentVariant = umbVariantCtrl.content.variants.filter( (x) => x.active )[0];
// Lets check if we have variants and we are on the default language then ...
if(umbVariantCtrl && umbVariantCtrl.content.variants.length > 1 && !currentVariant.language.isDefault && !currentCulture && !currentProperty.unlockInvariantValue) {
//This property is locked cause its a invariant property shown on a non-default language.
//Therefor do not validate this field.
return;
return;// do not return anyway..
}
// if we have reached this part, and there is no culture, then lets fallback to invariant. To get the validation feedback for invariant language.
currentCulture = currentCulture || "invariant";
var watcher = null;
var unsubscribe = [];