Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQ5 AEM: how to get a component by name within a dialog using javascript

I know this will probably a simple question, but I'm new to CQ5 and AEM in general.

I have a cq:Widget node which is a simple textfield.

 <rowtitlevalue
     jcr:primaryType="cq:Widget"
     fieldLabel="Row Title Value"
     name="./rowtitlevalue"
     xtype="textfield"
     disabled="true"/>

Now at the moment within my JavaScript, I'm currently accessing it via

var textfield = panel.findByType('textfield')[1];

which works fine (there's another textfield before this one, hence the 1 in the array.

MY QUESTION: how do I look for this field using it's NAME attribute within my javascript.

Any help would be appreciated.

Also, I'm using this object to run the following:

if (show != undefined) {
    textfield.enable();
    textfield.show();
}
else if (show == undefined) {
    textfield.disable();
    textfield.hide();
}

The JavaScript is located within the Component Based ClientLibs.

And this is the Listener that I have under the checkbox that defines the value of SHOW within the javascript (which is working fine).

<listeners
jcr:primaryType="nt:unstructured"
loadcontent="function(field,rec,path){Ejst.toggleRowTitle(field);}"
selectionchanged="function(field,value){Ejst.toggleRowTitle(field);}"/>

Please let me know if you see any problems with this.

Appreciate it in advance

like image 322
Alisneaky Avatar asked Dec 19 '22 16:12

Alisneaky


1 Answers

The CQ.Dialog API defines the getField( String name) method which returns a field with the given name. In case more than one field with the same name exists, it returns an array of those fields.

Thus finding parent of xtype dialog instead of panel as shown below would solve this.

Ejst.toggleRowTitle = function(checkbox) {
    var dlg = checkbox.findParentByType('dialog');
    var rowTitleField = dlg.getField('./rowtitlevalue');
    // perform required operation on rowTitleField
}
like image 64
rakhi4110 Avatar answered Dec 22 '22 05:12

rakhi4110