I have a checkbox and a textfield. If the checkbox is checked the textfield is an required field. If the checkbox is not checked the textfield is not required.
It works fine when changing the page properties of an existing page. I can only save the page if I filled the textfield when the checkbox is checked and I can save it when the checkbox is not checked and the textbox is not filled.
But if I creat a new page the changing of the checkbox has no effect to the create Button.
The validation works I can see that the required textbox changes if I check or uncheck the checkbox. That meens the red corner appears and diappears and in the HTML I see the "required".
But the create Button is grey until I first add something into the textfield. I can then remove it an save the page no matter if I added something in the required textfield or not. So there is the flag: required but the create button do not really works correctly.
So how can I "add" the "refresh" of the "create Button" if I change the textfield from required to not required or the other way round? Like an "validate the page create page again" or something!?
Views
Replies
Total Likes
Hi @anjabed
Could you post here some snapshot of the dialog definition and of the custom validation JS (supposing you added one) ? It would be easier get some advice once your specific scenario becomes more clear.
Sure.
The field definitions in the page:
<abc jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/fieldset">
<items jcr:primaryType="nt:unstructured">
<textfeld cq:showOnCreate="{Boolean}true" jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield" fieldLabel="InhaltTextfeld" name="./textfeld123" validation="checkbox-textfeld-validation"/>
<checkbox cq:showOnCreate="{Boolean}true" jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/checkbox" checked="{Boolean}true" fieldLabel="Checkbox" name="./checkbox123" text="Checkbox" validation="checkbox-textfeld-validation"/>
</items>
</abc>
the js for the validation
$(window).adaptTo('foundation-registry').register('foundation.validation.validator', {
selector: '[data-foundation-validation~="checkbox-textfeld-validation"]',
validate: function (el) {
//check if checkbox is checked
var checked = $('input[name="./checkbox123"]:checked').val();
console.log ("Checkbox: " + checked);
if (checked)
{
$('input[name="./textfeld123"]').prop('required',true);
console.log ("Textfeld: true");
}
else
{
$('input[name="./textfeld123"]').prop('required',false);
console.log ("Textfeld: false");
}
console.log("Ende");
}
})
If I check or uncheck the checkbox I can see in the console the logging and in html I can see this:
But the create Button is grey until I add something to the textfield no matter if the textfield is required or not. After adding something the create turns blue and I can click it and save the page also I have removed the text from textflied and it is still required.
I hope this helps.
If I create the page and the open the properties dialog everthing works fine!
Views
Replies
Total Likes
Perhaps it helps: we actually use 6.5.18 on premise!
To reproduce the error.
I installed AEM OOTB 6.5. Installed SP 18.
Create a new page template Test Validation hide all properties except title and added my checkbox and textfield. Then I overlay the validations.js in apps and added my valdation for the textfield and checkbox.
(These changes I add into the package we.retail.test-validation.zip you can find here).
I tested and the problem occures. So you can now reproduce the error yourself if you want.
I the installed the newest SP 22 and tried it again. But the error is still there.
So either something is missing in my config or there is an error in OOTB creating page validation.
Can someone help?
Views
Replies
Total Likes
To add the zip. I had to zip it again. So it is a zip in zip! To install it you have to unzip it first!
@anjabed Did you find the suggestion helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
@kautuk_sahni Here is NO sugggestion!
Everything here is posted from me an is just a description of my problem! I have not found a solution! But found a similar problem without validation just create a mulitifield and mark multifield and the field under the multifield required. It just work when you edit a page but not when you create a page. So the button "Create" when creating a page does not check again before saving the new page. The editing page button "save&close" checks and so it finds out that the required fields are not filled.
I still need a solution for this!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies