Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

defaultValue property removed in coral numberfield in AEM 6.4?

Avatar

Level 3

Hi,

We are facing issue in making numberfield change from granite/ui/components/foundation/form/numberfield to granite/ui/components/coral/foundation/form/numberfield in AEM6.4.

As per this document, NumberField — Granite UI 1.0 documentation  the defaultValue property has been removed for 6.4

However the property exists for 6.3 -- NumberField — Granite UI 1.0 documentation 

How can we achieve Coral numberfiled along with defaultProperty in AEM 6.4?

smacdonald2008Arun Patidar​ any help on this?

Thanks in advance!!

1 Accepted Solution

Avatar

Correct answer by
Level 4

HI @sundarig90868210

You can achieve the same by using @DefualtValue.

Try the below:-

<number

                        jcr:primaryType="nt:unstructured"

                        sling:resourceType="granite/ui/components/coral/foundation/form/numberfield"

                        fieldDescription="Value of Product"

                        fieldLabel="Page value"

                        name="./testValue"/>

<number-default

                        jcr:primaryType="nt:unstructured"

                        sling:resourceType="/libs/granite/ui/components/coral/foundation/form/hidden"

                        name="./testValue@DefaultValue"

                        value="{Long}11"/>

Make sure name property remain the same with @DefaultValue appended in the hidden one.

View solution in original post

10 Replies

Avatar

Level 10

I am checking with the Touch UI team to see what is happening here.

Avatar

Community Advisor

Hi

Use "value" property insteadof "defaultValue" .



Arun Patidar

Avatar

Level 10

Nice suggestion - I am going to test this later today.

Avatar

Level 3

Hi Arun Patidar​,

I have tried your approach.

And there is one issue related to value property.

I gave value for coral numberfield.

1665008_pastedImage_0.png

After when i use this component in page, in dialog i am able to see the value initially.

1665009_pastedImage_1.png

After that i have authored with some value and saved it. If i open the dialog again and removed the authored value and save it again the value(which is supposed to be displayed) is not appearing in dialog.

Authored value:

1665010_pastedImage_2.png

Removed the authored value and opened the dialog again :

1665011_pastedImage_3.png

The value is not displaying.

Any help on this?

Avatar

Level 1

This happens because, as @arunpatidar said, the "value" property depends on jcr:created and jcr:lastModified, if they are different it means that the crx node was modified and therefore the crx value is shown (and "value" property is not used). The same happens when the properties jcr:created and jcr:lastModified are not present.

Avatar

Level 10

that is because you removed the value. If you remove the value - it's gone.

Avatar

Community Advisor

Hi,

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.

If you always need value property in case of empty you can add data attribute using granite:data node and set any property with default value and with the help of javascript on dialog load you can check if number filed is empty you can fill it from data attribute value.



Arun Patidar

Avatar

Correct answer by
Level 4

HI @sundarig90868210

You can achieve the same by using @DefualtValue.

Try the below:-

<number

                        jcr:primaryType="nt:unstructured"

                        sling:resourceType="granite/ui/components/coral/foundation/form/numberfield"

                        fieldDescription="Value of Product"

                        fieldLabel="Page value"

                        name="./testValue"/>

<number-default

                        jcr:primaryType="nt:unstructured"

                        sling:resourceType="/libs/granite/ui/components/coral/foundation/form/hidden"

                        name="./testValue@DefaultValue"

                        value="{Long}11"/>

Make sure name property remain the same with @DefaultValue appended in the hidden one.

Avatar

Level 3

Hi NegiCF​,

Thanks fo the solution. It worked.

Is this the proper way of defining defaultvalue in numberfield from 6.4 or is there any other reason for removal of delaultValue property from coral-numberfield?

Thanks,
Sundari.

Avatar

Community Advisor

@sundarig9086821,

 

Today, I struggled to set a default value for the numberfield.

 

I followed @Rohit-Negi's solution, but there was a problem. Setting the value property for the numberfield only works when new components are authored by the content authors, but existing component when configured, fail to pick up the default value.

I have spent some time in my evening coming up with a custom solution to solve this. Take a look here -> https://sourcedcode.com/blog/aem/aem-granite-ui-coral-3-number-field-default-value