Enforcing dialog field defaultValue

22 views
Skip to first unread message

Sebastian Kleine

unread,
Jan 10, 2023, 4:31:05 AM1/10/23
to Magnolia User Mailing List
Hello,
when I create a new dialog and set a defaultValue for a field it works. But changing an existing dialog and adding new fields the defaultValue does not get applied. I understand the reason that existing field-values should not be automatically changed/overwritten and Magnolia does not know if a field is new or not.

But is there a way to enforce the defaultValue, if a field is empty (and required). Imagine I have a component that is used 100 times. And I have to add a new (required) field with a given default value "abc". Someone would need to manually add the default value on every page save or I need to write a script to do that automatically. Is there a better way?
If the dialog field is required, than it would even generate an error when saving the form, because the field would be empty - even though it has a default value.

Or is it possible to have a feature request to Magnolia to add something like "enforceDefaultValueIfEmpty" property for dialog fields. That would for me massivly improve the defaultValue property.

Sebastian

Roman Kovařík

unread,
Jan 10, 2023, 7:08:24 AM1/10/23
to Magnolia User Mailing List, sebastian....@gmail.com
Hey Sebastian,

unfortunately the API allows only two strategies:
- apply default values (openDialogAction/populate=false)
OR
- read values from the persisted item (openDialogAction/populate=true)

We would recommend to use e.g. a groovy script to update all content when adding a new property.
Solving this on UI level could introduce inconsistencies as only edited items would be updated but non edited items would still miss the new property.

Regards 
Roman

Reply all
Reply to author
Forward
0 new messages