how to automate generate property in aem dialog

Avatar

Avatar

gayatrik8153299

Avatar

gayatrik8153299

gayatrik8153299

05-10-2020

Hi All,

We have a nav tab component and it has multifield and multifield has 2 text field (navid and navname).

We need to add one more property like some thing tabcount whenever the nav tab component used on the page.

and this property will not be shown in the dialog.

we need to auto generate this field in the backend.

we have created one test page and dropped nav tab component and we have authored 2 tabs.

each tab is multifield that contains nav id and nav name fields.

can we add one more property for each tab below navid and navname in crxde using java code.

Could you please assist on this and need your help urgent.

can we set property using resource?

gayatrik8153299_0-1601894831210.png

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Manjunath_K

Avatar

Manjunath_K

Manjunath_K

05-10-2020

@gayatrik8153299 

We have 2 options.

 

1. If this autogenerated tabcount need to be secured then add below mentioned afteredit listener in cq:listeners of component & whenever component is updated this generateTabCount() function will be triggered, you can write ajax request call to servlet in this method & in servlet you can iterate multifield resource node & using ModifiableValueMap you can add this tabcount if its not generated/exist.

 

<cq:listeners
jcr:primaryType="cq:EditListenersConfig"
afterdelete="function(){generateTabCount()}"
afterinsert="REFRESH_PAGE"
aftermove="REFRESH_SELF"/>

 

2. If this autogenerated tabcount can be exposed to client side/less secured, then you can create additional field in multifield as mentioned below with hidden class name so it will be hidden, write author clientlib listener & on dialog submit generate tabcount & assign values to these hidden tabcount dialog fields.

 

<tabCount
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
granite:class="unique-tab-count hidden"
name="./tabCount"/>

 

listener js

(function ($, $document) {
"use strict";
$(document).on("click", ".cq-dialog-submit", function (e) {
$('.unique-tab-count').each(function(index){
var tabCount = $(this).val();

if(!tabCount){ //if tab count not generated previously
tabCount = 'unique-id';// generate & assign unique id here
$(this).val(tabCount);
}
});
});
})($, $(document));

 

-Manjunath

Answers (0)