views:

54

answers:

2

Hello,
I'm using Grails scaffolding and would like to make a change in the default date during a create. Currently dates default to today's date. How would one default it to blank or no date?
Thanks,
Steve

A: 

Whatever the default value in your domain object is will show up in the form on create.

class Test {
    Date aDate
}

In that example the domain object has a non-nullable date, so the default value is a newly constructed date. If the domain object gets changed to:

class Test {
    Date aDate
    static constraints = {
        aDate(nullable:true)
    }
}

Then the default value for the date will be null and that's what will show up in the scaffolded create form.

If you want to set the default value explictly, just assign it with a domain object initializer:

class Test {
    Date aDate = Date.parse("yyyy-MM-dd", "2010-01-01")
    static constraints = {
        aDate(nullable:true)
    }
}
ataylor
Not sure why, but this didn't work for me. See below for what I had to do. Thanks for taking the time to answer though.
Steve Wall
+1  A: 

You can do grails install-templates and customize template, used for rendering.

In $PROJECT/src/templates/scaffolding/renderEditor.template there is method renderDateEditor which should be customized to your needs.

This customization will be applied to all new scaffolding operations.

uthark
Changing renderEditor.template - renderDateEditer as follows did the trick. Note the "value=none". Thanks for help! return "<g:datePicker name=\"${property.name}\" precision=\"${precision}\" value=\"none\" />"
Steve Wall