AEM 6.5 Pre-populate fileUpload image field in cq dialog - aem

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.

Related

Add granite:data to cq dialog textfield

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"
....

Fetch Text and Values both from Touch UI Dropdown in AEM

I have a static list of drop down,but i want to fetch both value and Text from the drop down in AEM touch UI.
<articleType
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/select"
fieldLabel="Article Type"
name="./articleType">
<items jcr:primaryType="nt:unstructured">
<select
jcr:primaryType="nt:unstructured"
text="Select Icon"
value=""/>
<article
jcr:primaryType="nt:unstructured"
text="Article"
value="article"/>
<video
jcr:primaryType="nt:unstructured"
text="Video"
value="video"/>
<infographic
jcr:primaryType="nt:unstructured"
text="Infographic"
value="graph"/>
</items>
</articleType>
Now I want to fetch it like <i class="article-icon icon" />. I can fetch "icon class" from "value" but i need to always have some test conditions to fetch the text.
So i want a solution for this.
I have used data sources for this kind of requirements. In the example listed below, a jsp file is used. You can very well create WCMUsePojo class and call it in a HTML to refer the dynamic text and value pairs.
Please check:
https://helpx.adobe.com/experience-manager/using/creating-granite-datasource.html

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>

Add custom image page property in CQ5

Every page in CQ5 can have an image attached to it in page properties. I need to add my own image property to be used in a component.
I am able to add small things as a check box using this link but when I add a new image tab in the page properties, even the existing image stops working.
Even if I can add another image dialog in the page, I am unable to fetch the new image. This is the new image dialog I've added. (see attachment)
I just want to use the image in the carousel [maybe fetch it using :
Resource r = page.getContentResource("image1");
Can someone please help me on this ? What properties do I at least need to make it work ?
You need to use an xtype of smartimage (or a version of this, e.g. html5smartimage).
Here's some sample code that will add two images in a dialog — imageOne and imageTwo. You need to make sure that the properties of your new image don't conflict with the existing one — namely the fileNameParameter, fileReferenceParameter, name and the name of the child node resType should be unique in the example below.
<items jcr:primaryType="cq:TabPanel">
<items jcr:primaryType="cq:WidgetCollection">
<imageOnePanel
jcr:primaryType="cq:Panel"
title="Image One Panel">
<items jcr:primaryType="cq:WidgetCollection">
<imageOne
jcr:primaryType="cq:Widget"
border="true"
ddGroups="[media]"
fileNameParameter="./imageOne/fileName"
fileReferenceParameter="./imageOneFileReference"
height="300"
hideLabel="true"
name="./imageOne/file"
xtype="html5smartimage">
<items jcr:primaryType="cq:WidgetCollection">
<resType
jcr:primaryType="cq:Widget"
ignoreData="{Boolean}true"
name="./imageOne/sling:resourceType"
value="foundation/components/image"
xtype="hidden"/>
</items>
</imageOne>
</items>
</imageOnePanel>
<imageTwoPanel
jcr:primaryType="cq:Panel"
title="Image Two Panel">
<items jcr:primaryType="cq:WidgetCollection">
<imageTwo
jcr:primaryType="cq:Widget"
border="true"
ddGroups="[media]"
fileNameParameter="./imageTwo/fileName"
fileReferenceParameter="./imageTwoFileReference"
height="300"
hideLabel="true"
name="./imageTwo/file"
xtype="html5smartimage">
<items jcr:primaryType="cq:WidgetCollection">
<resType
jcr:primaryType="cq:Widget"
ignoreData="{Boolean}true"
name="./imageTwo/sling:resourceType"
value="foundation/components/image"
xtype="hidden"/>
</items>
</imageTwo>
</items>
</imageTwoPanel>
</items>
</items>
Reusing code from the dialog & not giving unique properties might have caused you issues with adding a second image, though I'm not 100% from the error you're seeing.