Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

AEM Content Fragment Model Field - How to provide default value in value property but also accept empty values when editing

Avatar

Level 1

Hi all,

We are currently working on a project where another team handles editing content fragments. They have requested that the content fragment should have a default value when being created but also accept an empty string for the value. However, with the value property assigned there is no way to currently save an empty value.

Is there a possible workaround for this?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi, 

 I just tried one with a textField, and it works fine.

This is how I have defined my field:

EstebanBustamante_0-1712608846631.png

Whenever the field is empty, the "default value" will be displayed

EstebanBustamante_1-1712608971094.png

EstebanBustamante_2-1712609070045.png

If you refresh the page, the value will be populated again because if there is no value. This is the expected behavior and how a "default value" works, if none is set, then the default is set. If you are trying to avoid this behavior, then you are not really looking for a default behavior. I think your best option is to either use a placeholder with the default value as I suggested, or add the suggested value in the field description or tooltip.

Hope this helps

 

 



Esteban Bustamante

View solution in original post

4 Replies

Avatar

Community Advisor

Hi, 


I'm not sure if I understood correctly. Are you saying that prepopulating the field is not an option? If you're just looking for a way to display a default value without actually setting this value, I believe you could try using the placeholder as a "default value". If you have good name and description fields, this could be an alternative approach.

 

Hope this helps.



Esteban Bustamante

Avatar

Level 1

Hi Esteban,

Thank you for taking the time to reply.

Prepopulating the field is currently what we are doing with the set value property. However, there are specific fields that were requested to accept an empty value as well. 

When we set the value property with a predefined default value, we are unable to save the new empty value as it is replaced with the predefined default value once again. I wanted to see if there was a possibility to somehow have that predefined default value but also allow the option for the field to accept empty values and not fallback to the default value.

Avatar

Correct answer by
Community Advisor

Hi, 

 I just tried one with a textField, and it works fine.

This is how I have defined my field:

EstebanBustamante_0-1712608846631.png

Whenever the field is empty, the "default value" will be displayed

EstebanBustamante_1-1712608971094.png

EstebanBustamante_2-1712609070045.png

If you refresh the page, the value will be populated again because if there is no value. This is the expected behavior and how a "default value" works, if none is set, then the default is set. If you are trying to avoid this behavior, then you are not really looking for a default behavior. I think your best option is to either use a placeholder with the default value as I suggested, or add the suggested value in the field description or tooltip.

Hope this helps

 

 



Esteban Bustamante

Avatar

Level 1

Thank you for confirming Esteban. I was under this impression as well but wanted to explore in case there was a possible way to circumvent this behavior. Thank you for the help.