Home Forums Backend Issues (wp-admin) Set a default date on conditional date field


Set a default date on conditional date field

  • I was surprised to find out that date fields don’t have any option for a default. I was hoping to use “now” as a default and have it set to today’s date. The usage is I’ve got a checkbox field “contacted” for a record and when the user checks this field we want to record what date the contact was made. So I have a conditional date field that shows only after the checkbox is checked. I’d like that checkbox by default to show the current date.

    We could set that value after the form is processed using an action hook but in some cases the date will be in the past and the record is just being updated. So we still need to be able to change that date whe applicable.

    What I’d like to do is use some jquery and when the checkbox is ticked, the date field is populated with the current date and then shown.

    I’ve tried following this documentation about adding javascript actions using acf.add_action but I found I’m getting an error “Uncaught ReferenceError: acf is not defined” on list pages and on entry pages nothing is running. Do I need to wrap the code inside a Jquery ready function or something else?

Viewing 1 post (of 1 total)

The topic ‘Set a default date on conditional date field’ is closed to new replies.