Validation Touch UI dialog does not work when creating a page
Hi,
I have a page with multiple properties. I added some validations (for example that the date should be in the future or a text field has to be only 50 long) and all works fine except one.
I want that a text field ("name = ./ABC") is „required“ if a checkbox (name = ./def) is „checked“.
The data-foundation-validation „xyz“ I added to the text field ("name = ./ABC").
This works fine when changing page properties on an excisting page. But it needs to click sometimes the „save“ button to refresh it that the „required“ will be deleted.
My problem ist hat it does not when I creating the page.
The problem is this part in the validation.js.
„$(window).adaptTo('foundation-registry').register('foundation.validation.validator', {
selector: '[data-foundation-validation~="xyz"]',
validate: function (el)“
It will not be called when I check or uncheck the checkbox when creating a new page. When changing existing page properties it will be called and works.
Perhaps someone can help me!
Here the complete validation.js
(function(window, document, Granite, $) {
"use strict";
function initValidation() {
console.log("initValidation"); // is allways called
$(window).adaptTo('foundation-registry').register('foundation.validation.validator', {
selector: '[data-foundation-validation~="xyz"]',
validate: function (el) {
//check if ./def is checked
var def= $('input[name="./def"]:checked').val();
console.log ("2: " + def);
if (def){
el.setAttribute("required", "true");
console.log ("2: true");
}else{
el.removeAttribute("required")
console.log ("2: false");
}
}
})
}
$(document).on('change', function(){
console.log("Change");
initValidation();
})
})(window, document, Granite, Granite.$);

