Abstract
Business needs are constantly evolving, and developers have to keep up by updating existing AEM components to reflect ongoing changes. Sometimes it is necessary to add a new field with a predefined default value to an existing dialog. Upon testing the changes, we discovered an inconsistent behaviour: the default is only applied to newly created components. If the component has been edited even once, the defaults are not applied.
What is the reason for this inconsistency? AEM Granite Forms operate using a concept called “freshness.” The form is considered “fresh” if it hasn’t been edited at all. To be more precise, the algorithm matches jcr:created and jcr:lastModified / cq:lastModified properties.
Modified Component
A modified component – defaults won’t apply!
By default, Granite checks form freshness and applies the default value only if the form is fresh. There is another mode in which the form ignores the freshness and uses the default value whenever there is no data available. Unfortunately, these modes are available for modification only in the Granite form component, not in the Granite dialog.
Can we change this? For most of the fields, yes! For Select fields the solution is straightforward; just add a forceIgnoreFreshness boolean property to your Select field. This property does exactly what it says; it ignores form freshness and always applies the default if no value has been chosen.
Read Full Blog
Q&A
Please use this thread to ask the related questions.
Kautuk Sahni