defaultValue in Touch UI dialogs - AEM/CQ
Asked Answered
V

3

6

For classic UI there is a option to set defaultValue for fields, this is shown to user when user first time opens the dialog after dragging the component. If user clears the value in dialog and saves, on editing the dialog, value of field is not shown again.

For touch UI dialog, couldn't find the equivalent of defaultValue. There are following options

  1. emptyText - But this is kind of placeholder text. If user wants to save form without entering value, this is not useful.
  2. value - This shows the value when first time component is opened for authoring. But if user clears the value and saves. From the JCR structure the value is removed. But if user opens the dialog for editing, the value is again shown in the field, while this should be empty.

If there a equivalent of defaultValue in touch UI dialog or any other way of handling this (may be listeners or something else)

Vetchling answered 28/7, 2016 at 15:12 Comment(3)
In TouchUI only numberfield provides the attribute defaultValue you can look at Granite Documentation for different available fields at docs.adobe.com/docs/en/aem/6-1/ref/granite-ui/api/jcr_root/libs/…Lighten
What should happen if the user does not save the dialog at all? Should the value be stored in JCR anyway or should the JCR property be empty?Sacaton
As per the defaultValue behavior, the value in JCR is empty unless saved through dialog. I was looking for similar alternate for Touch UIVetchling
M
8

Instead of using defaultValue or value, I feel like you should be using cq:template node. You can achieve this by adding nt:unstructured type of node with cq:template name under the component. Like this:

_cq_template/.content.xml

<?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"
    xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
    jcr:primaryType="nt:unstructured"
    sampleProperty="Default value of sampe property">
M answered 28/7, 2016 at 19:53 Comment(2)
Checked cq:template, as soon as we drag component, the property value is saved in content JCR structure. This kind of works, though not exactly similar to defaultValue. We had checks based on property value to show author "Configure this component" on first time drag kind of text, so the check needs to be applied in different manner or may be default value needs to be different, against which we can apply check.Vetchling
This is SO obscure. I wasted half of the day trying to figure this out. ThanksBanzai
T
1

I'm planning to set a select field in the design dialog with dropdown for default values and then work with it in the cq-dialog with value="${cqDesign.type}"

Therm answered 23/8, 2018 at 4:46 Comment(0)
R
0

Since numberfield is also mentioned in this discussion. I have got value working instead of defaultValue in granite UI.

<numberOfResults
    jcr:primaryType="nt:unstructured"
    sling:resourceType="granite/ui/components/coral/foundation/form/numberfield"
    fieldLabel="Number Of Results"
    required="{Boolean}true"
    value="10"
    name="./numberOfResults"/>

Limitation (snippet from mentioned thread):

The value property values only persist if jcr:created and jcr:lastModified date is same for a component node in content. That means once component is authored, the dialog values will be fetched from save properties. Make this field mandatory if you wish to keep a value either default or authored value. That solves the problem of always populating it.

Thread Refer https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/defaultvalue-property-removed-in-coral-numberfield-in-aem-6-4/qaq-p/292673 for more details.

Russ answered 7/8, 2020 at 2:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.