Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

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

5 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 2

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 2

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.

Avatar

Level 1

We're looking for the same functionality as the original poster and I just want to clarify what they're asking for to make sure it's not an option.

 

What the original post is asking for is essentially what a cq:template would be for a component. Where upon creation the dialog fields can be populated with default values, but can then be cleared by the author and set to empty values. We're looking for the same functionality where a Json field will be populated with the structure we expect from the author, but can optionally be removed by the author.

 

Placeholder text doesn't solve the issue because it can't be copied or modified by the author and disappears as soon as they start entering text (actually placeholder text doesn't seem to work at all for json fields).

 

I've looked around for the equivalent of a cq:template for a content fragment and haven't found anything so I assume it's not possible, but I just wanted to make sure.