Hi.
We've been using adaptive forms on AEM 6.1.
As an author, is it possible to turn a field into mandatory only when its visibility and access expressions (on the script tab) evaluate both to true?
Or should I always write a validation expression in order to do that, repeating the visibility and access expressions?
As a developer, how can I make this easier for our website authors?
Thanks!
Regards,
Daniel.
Solved! Go to Solution.
With an Adaptive Form, you need to wait until the Adaptive Form is ready, not the document DOM.
Try the following:
window.addEventListener("bridgeInitializeStart", function(evnt) { //this function will be called after adaptive form is initialized // get hold of the guideBridge object gb = evnt.detail.guideBridge; //wait for the completion of adaptive forms gb.connect(function (){ console.log(mainJSVersion); initializeForm(); }) });
Note that the initializeForm() function contains all of my function code. Also, I have a variable in the script called "mainJSVersion" that simply contains the date and time of my last edit. Client-side caching with client-libs can be painful, so with the version or date and time of my last edit displaying in the console, I get confirmation that I have the current version.
Hi Daniel,
The functionality to "set" a mandatory property for a field was introduced in 6.1 Feature Pack 1. For the given use-case, you can follow the steps mentioned below:
a) Say, we are controlling visibility of a field Y based on a field's(say X) value.
b) On "value commit" script of X, you can write the following script,
if(this.value === "4"){ Y.visible = true; Y.mandatory = true; } else { Y.visible = false; }
A similar approach could be followed for "access" too.
Hope this solve's your use-case.
Thanks,
Rishi
Views
Replies
Total Likes
Hi Daniel
I've written a clientlib that
var widgetClassesToIgnore = [ 'guideButton', 'guideInstanceManager', 'guidePanel', 'guideTextDraw', 'guideToolbar', 'rootPanelNode' ]; function resetWidget(widget) { if (widgetClassesToIgnore.indexOf(widget.className) == -1) { widget.value = null; } if(widget.items) { widget.items.forEach(function(child) { resetWidget(child); }); } } window.addEventListener("bridgeInitializeStart", function(event) { var gb = event.detail.guideBridge; gb.connect(function() { // first time initialization: all widgets that are not visible shall // not be validated gb.visit(function(widget) { widget.validationsDisabled = !widget.visible; }); // every time visibility changes let's check whether the widget // shall be validated or not gb.on('elementVisibleChanged', function(event, data) { var widget = gb.resolveNode(data.target.somExpression); if (data.newText) { widget.validationsDisabled = false; } else { resetWidget(widget); widget.validationsDisabled = true; } }); }); });
My assumption is that fields that become invisible are not important for the form anymore and I don't want to have them in the payload once the form is submitted. That's why I set their values to null.
Regards,
Urs
Views
Replies
Total Likes
Thanks, Rishi!
Views
Replies
Total Likes
It sounds very nice, Urs. Thanks!
Views
Replies
Total Likes
With the AEM Forms 6.1FP1 (or later patches), the validations get auto disabled for hidden fields/panels. Please check that.
Views
Replies
Total Likes
With an Adaptive Form, you need to wait until the Adaptive Form is ready, not the document DOM.
Try the following:
window.addEventListener("bridgeInitializeStart", function(evnt) { //this function will be called after adaptive form is initialized // get hold of the guideBridge object gb = evnt.detail.guideBridge; //wait for the completion of adaptive forms gb.connect(function (){ console.log(mainJSVersion); initializeForm(); }) });
Note that the initializeForm() function contains all of my function code. Also, I have a variable in the script called "mainJSVersion" that simply contains the date and time of my last edit. Client-side caching with client-libs can be painful, so with the version or date and time of my last edit displaying in the console, I get confirmation that I have the current version.
Thanks for your reply, its working now.
Can you please help me how to skip in-built validations and invoke custom validations when user submitted form.
We are using textbox component for email, i am trying to apply email format validations on this filed when user provided data. but when user submitted form these email validations not applying since validate() verifying only field is empty or not.
I found validate(); but not sure how to override it.
Views
Replies
Total Likes
Balu M wrote...
Thanks for your reply, its working now.
Can you please help me how to skip in-built validations and invoke custom validations when user submitted form.
We are using textbox component for email, i am trying to apply email format validations on this filed when user provided data. but when user submitted form these email validations not applying since validate() verifying only field is empty or not.
I found validate(); but not sure how to override it.
Hi
If your primary question is answered ans working for you.
I would request you to please mark this question as answered and create a new post for followup question.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
Hi Kautuk Sahni,
I tried to Mark it as answer but i could not find option, i have posted my question in existing thread.
Views
Replies
Total Likes