Setting a default date value in form builder

In form builder I'm attempting to set a default date value of 1-Jan-2010
for a date field.

I've tried the following in the 'Default Data Value' field:

  1. 2010-01-01 does not give an error when building the form but
    doesn't work. I'm presented with today's date as the value to edit and not
    2010-01-01
  2. *date('*2010-01-01') give the error: Invalid cast of data
    [date(2010-01-01)] to type Date in form Retailer details (new)
    https://www.commcarehq.org/a/colalife/apps/view/1af5843ab31d3c76aac0aa43cf0e2361/modules-0/forms-1/ in
    module "Retailers"
  3. date(2010-01-01) gives the same Invalid cast error as above

I've just checked Confluence and that tells me that functions aren't
supported so I guess that's why item 2 and 3 give errors.

Help!

Simon

Simon,

Setting the value to the latter two elements would require using the
"Default Value" field, rather than the "Default Data Value" field. I'm very
surprised to hear that setting the Default Data Value to 2010-01-01 is not
working, can you submit a bug from that form in CommCareHQ so we can take a
look?

As a workaround, you can try using "Default Value" and one of the latter
two expressions to see if that works.

-Clayton

··· On Tue, Dec 29, 2015 at 6:08 AM, Simon Berry wrote:

In form builder I'm attempting to set a default date value of 1-Jan-2010
for a date field.

I've tried the following in the 'Default Data Value' field:

  1. 2010-01-01 does not give an error when building the form but
    doesn't work. I'm presented with today's date as the value to edit and not
    2010-01-01
  2. *date('*2010-01-01') give the error: Invalid cast of data
    [date(2010-01-01)] to type Date in form Retailer details (new)
    https://www.commcarehq.org/a/colalife/apps/view/1af5843ab31d3c76aac0aa43cf0e2361/modules-0/forms-1/ in
    module "Retailers"
  3. date(2010-01-01) gives the same Invalid cast error as above

I've just checked Confluence and that tells me that functions aren't
supported so I guess that's why item 2 and 3 give errors.

Help!

Simon

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thanks. I have submitted a report from CommCareHQ as you suggest.

Regards

Simon
29/12/15

··· On 29 December 2015 at 16:09, Clayton Sims wrote:

Simon,

Setting the value to the latter two elements would require using the
"Default Value" field, rather than the "Default Data Value" field. I'm very
surprised to hear that setting the Default Data Value to 2010-01-01 is not
working, can you submit a bug from that form in CommCareHQ so we can take a
look?

As a workaround, you can try using "Default Value" and one of the latter
two expressions to see if that works.

-Clayton

On Tue, Dec 29, 2015 at 6:08 AM, Simon Berry simon@colalife.org wrote:

In form builder I'm attempting to set a default date value of 1-Jan-2010
for a date field.

I've tried the following in the 'Default Data Value' field:

  1. 2010-01-01 does not give an error when building the form but
    doesn't work. I'm presented with today's date as the value to edit and not
    2010-01-01
  2. *date('*2010-01-01') give the error: Invalid cast of data
    [date(2010-01-01)] to type Date in form Retailer details (new)
    https://www.commcarehq.org/a/colalife/apps/view/1af5843ab31d3c76aac0aa43cf0e2361/modules-0/forms-1/ in
    module "Retailers"
  3. date(2010-01-01) gives the same Invalid cast error as above

I've just checked Confluence and that tells me that functions aren't
supported so I guess that's why item 2 and 3 give errors.

Help!

Simon

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the
Google Groups "commcare-users" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/commcare-users/Wb7LGKpKBRY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi, @Simon_Berry, I faced the same situation and found a way to add a value by defaut in date data type, and the solution was to add single quotes '' date format yy-mm-dd.

In the field
Default Value: '2010-01-01'.

@Clayton_Sims