Fork me on GitHub

DropDownField based on AXA Style Guide

Adaptive Form provides ability to have custom widgets for a particular field. This sample creates a Drop Down List based on AXA Style Guide

The last section provides a step-by-step guide to build the DropDownField on your own. But if time doesn't persist, you can build the package and install it via Package Manager into your CQ-Instance

Note: This project has been built using the maven-archetype custom-appearance-archetype. The archetype only created the directory src/main/content/jcr_root/etc/clientlibs/custom. The rest of the directories are created on CRXDE and copied here using the vlt tool

Building

This project uses Maven for building (Minimum maven version 3.1.0). Common commands:

From the project directory, run mvn clean install to build.

Using with VLT

To use vlt with this project, first build and install the package to your local CQ instance as described above. Then cd to src/main/content/jcr_root and run

vlt --credentials admin:admin checkout -f ../META-INF/vault/filter.xml --force http://localhost:4502/crx

Once the working copy is created, you can use the normal vlt up and vlt ci commands.

Specifying CRX Host/Port

The CRX host and port can be specified on the command line with mvn -Dcrx.host=otherhost -Dcrx.port=5502 <goals>

How to create a DropDownField based on Axa Style Guide

Note: Make sure you save your changes after each and every step

As per the AXA style-guide we need a JavaScript and CSS file that can be downloaded as an npm package. The recommended approach in AEM is to create clientlibs for JavaScript and CSS and use those clientlibs to put the script in HTML Markup. For the same, we will create a clientlib in /etc/clientlibs/aemformsamples/.

Include Axa Style Guide in AEM as a clientlib.

Note: To upload files you can read this article

Note: In css.txt and js.txt files we mention the files that will be combined to form a single file and sent to the client. If you want minified files to be sent, then put the names of the minified files.

Modify the markup of Drop-down list to match the markup specified in Axa Style Guide

But still the options that you specify in the dialog are not visible in the Dropdown. To achieve that you need to modify widget.jsp to read the options that the user have specified in the dialog.

Note: guideField here represents the Model of the Guide Drop-down list which provides API to access the properties that user have specified in the dialog. To see how this is initialized you can have a look at the init.jsp in the OOTB dropdownlist component.

Making the Field work in Runtime

Now everything works fine in Authoring. Previewing the form also looks OK but the value selected in the AXA Drop-down list is not submitted. The reason for that is the Adaptive Forms runtime expects the input/textarea/select/button fields to be wrapped in a div element which should have a css Class with value equal to the Java Constant GuideContants GuideConstants.GUIDEFIELDWIDGET.

Adaptive Forms runtime then passes that div element to a jQuery Widget which we internally call as xfa widget. The XFA widget understands that HTML markup and passes the value from that markup to the client. Some xfa widgets remove the markup and insert their own.

The good thing is that we have a set of guides that help you create your own custom xfa widget and use it for your custom fields