tonym tonym - 1 month ago 27
Javascript Question

AEM 6.1 Checkbox Enable/Disable Tag Attributes

I have created my first AEM component. The functionality is very simple: when the component is dropped onto a page, the component will generate content that contains a URL and provide a configuration option to open the URL in a new window.



<a class="btn" href="${properties.ctaUrl}" target="${properties.ctaNewwindow}">${properties.ctaLabel}</a>





How do I specify:
target="_blank"
? The
xtype
of
ctaNewwindow
is:
checkbox
.

Answer

If your checkbox value is: "true" when the checkbox is checked, you can simply use an inline expression like this:

<a class="btn" href="${properties.ctaUrl}" target="${properties.ctaNewwindow != null && properties.ctaNewwindow.equals('true') ? '_blank' : '_self'}">${properties.ctaLabel}</a>

Or you can use: "_blank" directly in your checkbox definition as the value:

<required
    jcr:primaryType="nt:unstructured"
    sling:resourceType="granite/ui/components/foundation/form/checkbox"
    name="./required"
    fieldDescription="Check to open in new window."
    text="Open in new window"
    value="_blank"/>
<deleteRequired
    jcr:primaryType="nt:unstructured"
    sling:resourceType="granite/ui/components/foundation/form/hidden"
    name="./required@Delete"
    value="_blank"/>

And your code will work without any additional checks.

Comments