Expand my Community achievements bar.

SOLVED

Handling Optional Field Property - cq:dialog

Avatar

Level 5

Hello All - There is a cq:dialog for the page component for capturing the page properties. In that, I have a drop-down with two options for the authors to select and it is not a mandatory field. When the values are not selected, the productType property shouldn't be captured in jcr:content. Could some suggest how to handle this?


<productType
cq:showOnCreate="{Boolean}true"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
fieldLabel="Product Type"
name="./productType">
<items jcr:primaryType="nt:unstructured">
<household
jcr:primaryType="nt:unstructured"
text="Household"
value="HH"/>
<commercial
jcr:primaryType="nt:unstructured"
text="Commercial"
value="COM"/>
</items>
</productType>

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

 

As per your xml shared you have two options in the dropdown and by default the first option will be showed when the dialog is opened and when dialog is closed the value will be stored with property name under jcr:content

 

You can add below property to the productType node which will show the place holder text on dialog open and if no value is selected from dropdown, value will not be stored in jcr:content. "Select Value" text can be any value as per your requirement.

 

Screen Shot 2021-01-07 at 5.35.00 PM.png

Dialog will be showed as below

Screen Shot 2021-01-07 at 5.35.53 PM.png

For more options on select refer

 

https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/granite-ui...

View solution in original post

8 Replies

Avatar

Correct answer by
Community Advisor

Hi,

 

As per your xml shared you have two options in the dropdown and by default the first option will be showed when the dialog is opened and when dialog is closed the value will be stored with property name under jcr:content

 

You can add below property to the productType node which will show the place holder text on dialog open and if no value is selected from dropdown, value will not be stored in jcr:content. "Select Value" text can be any value as per your requirement.

 

Screen Shot 2021-01-07 at 5.35.00 PM.png

Dialog will be showed as below

Screen Shot 2021-01-07 at 5.35.53 PM.png

For more options on select refer

 

https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/granite-ui...

Avatar

Level 5
I have added but the dropdown is not showing the empty text. Can you tell me what is wrong here? <productType cq:showOnCreate="{Boolean}true" jcr:mixinTypes="[cq:ReplicationStatus]" jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/select" emptyText="---------- Select Product Type ----------" fieldLabel="Product Type" name="./productType"> <items jcr:primaryType="nt:unstructured"> <household jcr:primaryType="nt:unstructured" text="Household" value="HH"/> <commercial jcr:primaryType="nt:unstructured" text="Commercial" value="COM"/> </items> </productType>

Avatar

Community Advisor
I dont see any issues, it might be a cache issue, can you change the value of dropdown and check the changes are reflecting.

Avatar

Level 5
I can see the changes now. Since I have already selected the value, it didn't show up. when I create a new one it shows up. My requirement is say, if I select any value and then it should let me to unselect the selected option. Please let me know if this is doable.

Avatar

Community Advisor

You can add emptyOption {boolean} true which will add empty option to the dropdown and on selecting it will remove the previously selected value.

 

Refer coral api documentation for different options shared in my first comment

 

https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/granite-ui...

Avatar

Level 5
Do we have any "emptyOption" property available for dialog (Classic UI dialog) ?