Set default value for date picker on form 2.0 | Community
Skip to main content
February 22, 2017
Question

Set default value for date picker on form 2.0

  • February 22, 2017
  • 2 replies
  • 6813 views

If I specify a "Today" in the form editor the value does not update. So tomorrow it would still read 2/22/2017. What I want, is for the default value in the field to be set to TODAY such that it updates for the current day. What is the best way to accomplish this? Or is the documentation someone can point me towards.


Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Josh_Hill13
Level 10
February 22, 2017

Use the {{system.dateTime}} token in a CDV flow step triggered by Fills Out Form will work.

More clearly:

Fills Out Form

Change Data Value: Date = {{system.dateTime}}

You can probably take the Date field out of your form unless you are asking the person for a specific date.

Jason_Reber__TH
Level 2
February 1, 2018

Hi Dean,

I have the same issue I think - I have a date input on a form, and I'd like to set the default value in that input = the date on which the user views the form. I tried specifying a Default Value of "{{system.date}}" in the field in the Form Builder in Marketo, but it doesn't work when viewing the live form.

@Josh - I believe what you have proposed would change the value only after the user had submitted the form, and would not change the default value seen by the user before they have submitted the form. Anyone have any ideas how to accomplish this from within Marketo?

SanfordWhiteman
Level 10
February 2, 2018

Like so:

MktoForms2.whenReady(function(form){

  var now = new Date();

  form.setValues({

    YourFormField : [now.getFullYear(),now.getMonth()+1,now.getDate()]

                    .join("-")

                    .replace(/-(\d)\b/g,"-0$1")

    });

});

Avoid the temptation to use the simpler-seeming

new Date().toISOString().substr(0,10) 

because that will give timezone-related surprises.

Caroline_Graha1
Level 2
July 5, 2018

@Sanford Whiteman ,

I am having the same issue as Josh; we would like to be able to add this custom code in place in order to restrict users from choosing dates in the past/force them to instead select a future date.

How do I go about adding in the code below to my form?

Thanks in advance for any help!

Caroline