formie icon indicating copy to clipboard operation
formie copied to clipboard

Allow Object Templates as the default value

Open MoritzLost opened this issue 4 months ago • 4 comments

What are you trying to do?

I sometimes need to set default values for hidden or visible fields that are computed from user data, URL parameters, path segments, or something else.

For example, I have an event registration where I need to set custom values:

  • Some fields are set based on custom User fields of the current user (not the ones already offered as prefill options by Formie)
  • A hidden field Selected event is populated based on the ID of the event that is passed as a query parameter.
  • A hidden field Event cost is populated with the cost of the event (taken from a Money field on the event entry). This is used in turn to hide some other payment-related fields if the cost is 0 (free event).

Right now I'm setting all of that either through hooks or using Twig where the form is rendered. But both of those methods are opaque to other authors working with the form.

What's your proposed solution?

All of the above could be solved within Formie's interface if it was possible to use Twig templates to set the default value. Similar to Object Templates used for many of Craft's core settings. This would allow us to keep much of this custom logic contained within the Formie form, and make it visible to authors.

A solid first step would be to allow Twig templates as an option for hidden fields, which already provide more options to set the default value. Ultimately, having this option for all fields would be incredibly useful.

Additional context

No response

MoritzLost avatar Oct 27 '25 13:10 MoritzLost