3

Situation:

We have an AEM 6.4 Touch UI dialog and a number of existing component instances that were created through this dialog.

Now we want to add an additional boolean property (checkbox) to the dialog.

The default value of the new property should be true / checked.

Expected Result:

When an editor opens the updated dialog for an existing component, I would expect that the dialog shows the new checkbox checked since this is the default and the JCR contains no value for existing components.

Actual Result:

The dialog shows the checkbox unchecked for an existing component that has no value for this property in the JCR.

Surprisingly, the dialog shows the checkbox checked for a freshly created component!

Any ideas? Thanks.

Snippet of the checkbox inside the .content.xml file below.

<newProperty
  jcr:primaryType="nt:unstructured"
  sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
  checked="{Boolean}true"
  name="./newProperty"
  text="The recently added new property"
  uncheckedValue="{Boolean}false"
  value="{Boolean}true"
/>
John Goofy
  • 866
  • 8
  • 22
  • you need to add a listener and enable necessary checkbox – dzenisiy Feb 21 '20 at 19:51
  • Thanks, but why is that so? Is this a bug or intended behavior? I couldn't find any hints in the documentation when AEM applies default values and when it doesn't, so my assumption was that it would always do so when a value is "empty" in the JCR, but that seems to be wrong. – John Goofy Feb 23 '20 at 11:50

3 Answers3

1

It certainly will require a JS validation, since the absence of the value is falsy for the dialog.

ronnyfm
  • 1,973
  • 25
  • 31
  • Thanks, but why is that so? Is this a bug or intended behavior? I couldn't find any hints in the documentation when AEM applies default values and when it doesn't, so my assumption was that it would always do so when a value is "empty" in the JCR, but that seems to be wrong. – John Goofy Feb 23 '20 at 11:50
0

Your example should always work, no need for extra js or properties. When you say there is no existing 'value' for this property, do you mean this property is not there or it is empty? Because an empty property would still have a value, in this case an empty string, resulting in it being read as false and the checkbox being empty. A new componenty does not have this property, resulting in the default being shown. If this does not work as designed, could you extend your example by adding all current properties of the component?

YFrickx
  • 108
  • 1
  • 10
-1

@John Goofy - you just need to add below property

'ignoreData={Boolean}true'

then, your node becomes

<newProperty
  jcr:primaryType="nt:unstructured"
  sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
  checked="{Boolean}true"
  name="./newProperty"
  text="The recently added new property"
  uncheckedValue="{Boolean}false"
  value="{Boolean}true"
  ignoreData="{Boolean}true"
/>

please let me know, if it doesn't work for you.

raju muddana
  • 154
  • 1
  • 14
  • According to the [documentation](https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/granite-ui/api/jcr_root/libs/granite/ui/components/foundation/form/checkbox/index.html), this would always ignore the JCR and always check/uncheck the checkbox according to the defaults. I need something different: only if there is *no value saved in the JCR*, the checkbox should use the default; if there is a value in the JCR, the checkbox should use that. – John Goofy Feb 25 '20 at 10:28
  • @JohnGoofy - Can you please try with ignoreData="{Boolean}false"? I tested, by default it is taking 'default value', once you save/author value it is picking up that value. It should work! – raju muddana Feb 25 '20 at 14:39