Playing with custom validations (i need to start doing this) This works... def validate errors.add :date_of_birth, 'is not a valid date' if Chronic.parse(date_of_birth.to_s).nil? end Trouble is when the form is re-rendered it's lost the users original selection - how do i fix it up?
on 2009-04-10 11:32
on 2009-04-10 12:07
thinking this through maybe this is the problem <td> <%= date_select 'enquiry', 'date_of_birth', :order => [:day, :month, :year], :start_year => 1950, :end_year => 2000, :include_blank => true %> is the include blank the problem (maybe it's getting blanked on the re-render)?
on 2009-04-10 12:31
bingo bob wrote: > > thinking this through maybe this is the problem > > > <td> <%= date_select 'enquiry', 'date_of_birth', :order => [:day, > :month, :year], :start_year => 1950, :end_year => 2000, :include_blank > => true %> > > is the include blank the problem (maybe it's getting blanked on the > re-render)? this looks like the problem to me - but how do i fix it? I'd like to show a blank on the initial form but not when a validation fails and the form is shown again (the user should see the original selection?
on 2009-04-11 01:15
No, the include_blank is not the problem I think. date_select automatically selects the value given in @enquiry.date_of_birth... The problem must be somewhere else. Are you sure @enquiry is not reset? A mistake I used to make is to redirect from the create to the new action instead of directly rendering the new template from the create action when rerendering the form. anyway, this is just a guess... I need to see how exactly you are rendering the form. On Apr 10, 11:31 am, bingo bob <email@example.com>