Reputation: 1856
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
emptyText
- But this is kind of placeholder text. If user wants to save form without entering value, this is not useful.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)
Upvotes: 6
Views: 12704
Reputation: 2667
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.
Upvotes: 0
Reputation: 23727
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}"
Upvotes: 1
Reputation: 523
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">
Upvotes: 8