Add granite:data to cq dialog textfield - aem

I am trying to create a validation function for a textfield depending on the content of other textfield in a cq dialog in AEM 6.5.
I am trying to send within the cq:data the textfield name but I can get AEM to render these data attributes on DOM.
This is a piece of the cq dialog
<creditsTitle
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Credits Title"
name="./creditsTitle_t"/>
<creditsValue
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
fieldLabel="Credits"
validation="custo-validation"
name="./creditsValue_t">
<granite:data jcr:primaryType="nt:unstructured"
dependent-name="creditsTitle_t"/> </creditsValue>
And here is a ss of what gets rendered:
I want to be able to send to the "custo-validation" a parameter with the name of the field that it needs to check,in this case is the one above (creditsTitle_t), but it can be anywhere.
So far the only way I have found is with the granite:data but i can't get it working

Your code looks good. just make sure you're adding the granite namespace at the top of the file
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
sling:resourceType="cq/gui/components/authoring/dialog"
....

Related

cq:showOnCreate not working with RTE on Page properties

We are using an RTE field in the page properties. The issue here is, this field doesn't render in the page properties when author is creating the page. Is this a known issue with AEM? Is there any workaround for this?
<bannerText
cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog/richtext"
fieldLabel="Banner text"
fieldDescription="This text describes the banner message."
required="true"
name="./bannerText"
useFixedInlineToolbar="{Boolean}true">
<rtePlugins jcr:primaryType="nt:unstructured">
<format
....
<bannerText?>
PS: We are using AEM 6.5
Thanks in advance!

AEM 6.5 Pre-populate fileUpload image field in cq dialog

New to AEM, I am trying to programatically populate an fileUpload image dropzone, and silently triggered its drop event as if user had manually drop an image asset to it. Is there a way to do this?
Say I have a cq_dialog with two fileUpload image fields (set to no upload, only droppable from asset allowed), one was already populated prior, the other is empty. Upon dialog load, I want to populate the empty one with the image asset from the populated one as a default.
The snippets of the cq_dialog looks like this:
<imageontopWrap
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container"
class="layout-showhide-targets"
showhidetargetvalue="imageontop">
<items jcr:primaryType="nt:unstructured">
<image1
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog/fileupload"
autoStart="{Boolean}false"
allowUpload="{Boolean}false"
class="cq-droptarget"
fieldLabel="Image Asset"
fileReferenceParameter="./myImageTopPath"
mimeTypes="[image]"
multiple="{Boolean}false"
name="./myImageTop"
title="Upload Image Asset"
useHTML5="{Boolean}true"/>
<altText1
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="Alt Text"
name="./myImageTopAltText"/>
</items>
</imageontopWrap>
<imageonleftWrap
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/container"
class="layout-showhide-targets"
showhidetargetvalue="imageonleft">
<items jcr:primaryType="nt:unstructured">
<image2
jcr:primaryType="nt:unstructured"
sling:resourceType="cq/gui/components/authoring/dialog/fileupload"
autoStart="{Boolean}false"
allowUpload="{Boolean}false"
class="cq-droptarget"
fieldLabel="Image Asset"
fileReferenceParameter="./myImageLeftPath"
mimeTypes="[image]"
multiple="{Boolean}false"
name="./myImageLeft"
title="Upload Image Asset"
useHTML5="{Boolean}true"/>
<altText2
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/textfield"
fieldLabel="Alt Text"
name="./myImageLeftAltText"/>
</items>
</imageonleftWrap>
I had created a clientLib for this cq_dialog, just wasn't sure the js codes to copy the image reference and trigger the drop using script.
Any help is much appreciated.
Here is the mechanism through you can achive what you require I hope. I am not sure about the exact js code though for which you have to do some googling on listners.
On dialog load, store the reference of the first image drop container in a js variable.
Then find the path of the image that is being stored/authored in the first image container.
Populate the same path in the second image drop path.
As I said, above is just a mechanism to help how you can achive your requirement.

How to use cq:editConfig Property in AEM 6.0

In AEM 6.0, I am having a component and, it has a text field and one video file uploader. I want to enable the drag and drop of this video from the content finder. My normal upload using the dialog is working, but this drag and drop is not working. I searched and found out that I can do this by using cq:editConfig. Can somebidy tell me that how can I do this?
Define the cq:dropTargets, as a child of the cq:editConfig node to configure the list of drop targets that can accept a drop from an asset of the content finder.
In your case, for a video, you can refer the foundation/components/video whose edit config is shown below.
<cq:editConfig jcr:primaryType="cq:EditConfig" cq:layout="editbar">
<cq:dropTargets jcr:primaryType="nt:unstructured">
<video jcr:primaryType="cq:DropTargetConfig" propertyName="./asset">
<parameters jcr:primaryType="nt:unstructured"
sling:resourceType="foundation/components/video"/>
</video>
</cq:dropTargets>
</cq:editConfig>
Also make sure you specify the ddGroups and ddAccept properties on the html5smartfile widget used for video file upload component.
Refer Configuring the Edit Behaviour of a component to get more insights on configuring the edit config and its child nodes.
You must be careful doing this because it can have an unexpected side effect of changing your component type to the type specified in the drop target.
To avoid that happening, you can distinguish between component type and target type by using this format:
<cq:dropTargets jcr:primaryType="nt:unstructured">
<video
jcr:primaryType="cq:DropTargetConfig"
accept="[video/.*]"
propertyName="./asset">
<parameters
jcr:primaryType="nt:unstructured"
sling:resourceType="myfolder/components/videoandtext">
<video
jcr:primaryType="nt:unstructured"
sling:resourceType="foundation/components/video"
/>
</parameters>
</video>
</cq:dropTargets>
See here for more info: Drop Target Issue

How to use richtext in multifield (in CQ5 dialog)? (prevent "this.el.dom is undefined" error)

I have created a custom component, and try to use RTE (xtype="richtext") inside the multifiled in my dialog.
Now, when I try to delete item, or after dialog was closed & reopened add another one the dialog will neither close, nor save the data with OK button.
dialog.xml:
<myField
jcr:primaryType="cq:Widget"
name="./myField"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
xtype="richtext">
</fieldConfig>
</myField>
Sham HC posted 2 solutions at AEM FAQ's:
Use textfield instead of a richtext Or try not to use a richtext in a multifield.
If richtext in a multifield is required then follow below and verify in your development envirnoment.
Overlay /libs/cq/ui/widgets/source/widgets/form/RichText.js
At the overlayed file for the method syncValue (Line 910) replace [1] with [2].
[1] this.el.dom.value = html;
[2] if(this.el.dom){this.el.dom.value = html;}
The problem is that I would like to use make it without changing Adobe's code.
I have found a workaround, that does not require changing CQ widget's code.
You need to set richtext's destroy event handler, to create dummy this.el.dom:
<myField
jcr:primaryType="cq:Widget"
name="./myField"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
xtype="richtext">
<listeners
jcr:primaryType="nt:unstructured"
destroy="function() {this.el.dom={};}"/>
</fieldConfig>
</myField>
<fieldConfig
jcr:primaryType="cq:Widget"
height="{Long}100"
xtype="richtext">
<listeners
jcr:primaryType="nt:unstructured"
destroy="function() {this.el.dom={};}"/>
</fieldConfig>

Can multiple smartimage xtypes appear on one dialog tab in AEM?

The out of the box (OOTB) page properties dialog in Adobe Experience Manager (AEM) (CQ5) provides an Image tab. I would like to add a couple more images to the dialog, but I don't want to create a separate tab for each one.
For instance, is there a way to include an image on the "Advanced" tab within a dialogfielset? I tried this, but it does not seem to render properly.
One thing I am considering is to extend the slideshow xtype and each image would be a separate "slide"
Are there better approaches?
It's possible to have multiple smartimage xtypes on a tab!
Widgets API document for smartimage:
Note that the component is mainly designed for use on a separate
dialog tab. You may use the component inside a
CQ.Ext.layout.FormLayout optionally if you provide a suitable height
setting.
Here are codes for dialog:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Dialog"
height="{Long}600"
title="dialog"
xtype="dialog">
<items
jcr:primaryType="cq:Widget"
xtype="tabpanel">
<items jcr:primaryType="cq:WidgetCollection">
<panel
jcr:primaryType="cq:Panel"
title="Panel with two Images">
<items jcr:primaryType="cq:WidgetCollection">
<firstimage
jcr:primaryType="cq:Widget"
cropParameter="./firstimage/imageCrop"
ddGroups="[media]"
fieldLabel="first image field"
fileNameParameter="./firstimage/fileName"
fileReferenceParameter="./firstimage/fileReference"
height="{Long}200"
name="./firstimage/file"
rotateParameter="./firstimage/imageRotate"
title="First Image"
width="{Long}200"
xtype="html5smartimage"/>
<secondimage
jcr:primaryType="cq:Widget"
cropParameter="./secondimage/imageCrop"
ddGroups="[media]"
fieldLabel="second image field"
fileNameParameter="./secondimage/fileName"
fileReferenceParameter="./secondimage/fileReference"
height="{Long}200"
name="./secondimage/file"
rotateParameter="./secondimage/imageRotate"
title="secondimage"
width="{Long}200"
xtype="html5smartimage"/>
</items>
</panel>
</items>
</items>
</jcr:root>
And the following is the result: