Adaptive forms - visibility/access expressions and mandatory option

Avatar

Avatar

daniel_henriqu1

Avatar

daniel_henriqu1

daniel_henriqu1

11-04-2016

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.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

sixteenlabsinc

Avatar

sixteenlabsinc

sixteenlabsinc

30-11-2016

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.

Answers (8)

Answers (8)

Avatar

Avatar

Balu_M

Avatar

Balu_M

Balu_M

07-12-2016

Hi Kautuk Sahni,

I tried to Mark it as answer but i could not find option, i have posted my question in existing thread.

Avatar

Avatar

kautuk_sahni

Community Manager

Total Posts

5.6K

Likes

961

Correct Answer

1.1K

Avatar

kautuk_sahni

Community Manager

Total Posts

5.6K

Likes

961

Correct Answer

1.1K
kautuk_sahni
Community Manager

05-12-2016

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

Avatar

Avatar

Balu_M

Avatar

Balu_M

Balu_M

30-11-2016

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.

Avatar

Avatar

deepak_k_

Employee

Avatar

deepak_k_

Employee

deepak_k_
Employee

17-04-2016

With the AEM Forms 6.1FP1 (or later patches), the validations get auto disabled for hidden fields/panels. Please check that.

Avatar

Avatar

daniel_henriqu1

Avatar

daniel_henriqu1

daniel_henriqu1

14-04-2016

It sounds very nice, Urs. Thanks!

Avatar

Avatar

daniel_henriqu1

Avatar

daniel_henriqu1

daniel_henriqu1

14-04-2016

Thanks, Rishi!

Avatar

Avatar

urs_h_

Avatar

urs_h_

urs_h_

14-04-2016

Hi Daniel

I've written a clientlib that

  • disables validation on widget and widgets within panels (even nested)
  • clears the value of invisbile widgets
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

Avatar

Avatar

rishim22446870

Avatar

rishim22446870

rishim22446870

13-04-2016

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