Adaptive forms - visibility/access expressions and mandatory option

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)

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)

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

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.

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

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