- My goal: I want DateTime input in a form to be prefilled with current time
- Issue: doesn't work with "new Date()" as a default
Hey @pavelgur ,
I understand your issue. The expression {{ new Date() }}
doesnβt work as expected inside a Form component because each field in the form is bound to a specific column name from your database table. When you view or edit the form, it automatically displays the existing value from the database β including date/time fields β instead of overriding it with {{ new Date() }}
.
If you're trying to show the current date and time only when the field is empty (such as during a "create new record" flow), you'll need to use a conditional default value. Here's how you can handle that using a transformer or default logic:
Example workaround using a transformer:
In the fieldβs default value, use:
return {{ table4.selectedRow.signup_date || new Date().toISOString() }}
This way:
- If there's an existing value (
signup_date
) in the form data, it will be shown. - If it's
null
or undefined (like during creation), it defaults to the current date/time.
Visual explanation:
Suppose your database has this existing
signup_date
value:
In that case, the form will always show that value unless overwritten manually or via logic like the transformer above.
Let me know if you're setting this for new submissions or updating existing ones β the handling differs slightly in each case.
When you view or edit the form, it automatically displays the existing value from the database β including date/time fields
It doesn't. When I open the form, it's always empty.
If you're trying to show the current date and time only when the field is empty
I simply want to always show the current dateTime unconditionally.
Nevermind -- I have solved the problem by triggering Reset of the form when I open it.