Validation on page properties works but Create Button does not change correctly | Community
Skip to main content
anjabed
Level 2
February 11, 2025

Validation on page properties works but Create Button does not change correctly

  • February 11, 2025
  • 2 replies
  • 788 views

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!?

2 replies

Tethich
Community Advisor
Community Advisor
February 11, 2025

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.

anjabed
anjabedAuthor
Level 2
February 12, 2025

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!

anjabed
anjabedAuthor
Level 2
February 12, 2025

Perhaps it helps: we actually use 6.5.18 on premise!

kautuk_sahni
Community Manager
Community Manager
March 5, 2025

@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!

Kautuk Sahni
anjabed
anjabedAuthor
Level 2
March 5, 2025

@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!