adding default date to model

6 views
Skip to first unread message

W.S. Hager

unread,
Jul 13, 2012, 8:36:18 AM7/13/12
to persevere...@googlegroups.com
Hi,

When I want to add a default value to the date property in my model, the date returned is a stale one:

...
dateFormat = require('dateformat');
...
date:{
            type:"string",
            format:"date",
            "default":dateFormat(new Date(),"isoDate")
},
...

The date in the new instance is not the current date but two days ago. When I restart persvr I get the current one. How can I fix this?

Thanks.

--

W.S. Hager
Lagua Web Solutions
http://lagua.nl


Ben Hockey

unread,
Jul 13, 2012, 11:01:53 PM7/13/12
to persevere...@googlegroups.com
with what you currently have, the dateFormat(new Date(),"isoDate") code is run once (when your model is defined) and this is why the date in the instance is old - in fact it will be the same for every instance that gets the default value.

fortunately, the "default" property can be a function that will be invoked for every instance that gets the default value.
"default": function () { return dateFormat(new Date(),"isoDate"); }

i believe that should work.

thanks,

ben... 

W.S. Hager

unread,
Jul 14, 2012, 6:44:24 AM7/14/12
to persevere...@googlegroups.com

Awesome! Thanks.

Op 14 jul. 2012 05:01 schreef "Ben Hockey" <neonst...@gmail.com> het volgende:
--
You received this message because you are subscribed to the Google Groups "Persevere" group.
To view this discussion on the web visit https://groups.google.com/d/msg/persevere-framework/-/rBjR64u8FcQJ.
To post to this group, send email to persevere...@googlegroups.com.
To unsubscribe from this group, send email to persevere-frame...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/persevere-framework?hl=en.
Reply all
Reply to author
Forward
0 new messages