History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GRAILS-1793
Type: Sub-task Sub-task
Status: Open Open
Priority: Critical Critical
Assignee: Graeme Rocher
Reporter: Marcel Overdijk
Votes: 6
Watchers: 8
Operations

If you were logged in you would be able to see more operations.
Grails
GRAILS-3413

Empty date field cannot be persisted using view

Created: 06/Nov/07 12:13 PM   Updated: 19/Sep/08 03:52 AM
Component/s: Persistence, TagLib
Affects Version/s: 1.0-RC1
Fix Version/s: 1.1

Time Tracking:
Not Specified


 Description  « Hide
As described on http://www.nabble.com/Date-not-valid%3A-date-can-be-null--tf4759422.html empty date fields cannot be persisted, resulting in an invalid date error message.

Using noSelection attribute as in

<g:datePicker name="myDate" value="${new Date()}" noSelection="['':'-Choose-']"/>

does not work.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Marc Guillemot - 10/Mar/08 08:03 AM
A workaround is:

1) use g:datePicker undocumented default="..." attribute in the view

<g:datePicker name="myDate" value="${new Date()}" noSelection="['':'-Choose-']" default="none"/>

2) remove the field from the map used for binding if some/all fields is/are empty

def excludes = []
if (!params.myDate_day)
excludes << "myDate"
bindData(myDomainObject, params, excludes)

(note that this has to be done in both save and update and that bindData has to be used rather than properties assignment)


dion gillard - 03/Apr/08 12:15 AM
I'm on Grails 1.0.1 and workaround 1) doesn't work for me.

I have:

<g:datePicker precision="day" name="publicLiabilityExpiry" value="${contractor?.publicLiabilityExpiry}" default="none" noSelection="${['':'--']}"/>

and need to use Option 2 to get it to work.


Marc Guillemot - 03/Apr/08 02:20 AM
Seems that I wasn't precise enough: (1) and (2) are not different alternatives but the 2 steps of the workaround