Skip to content

select as :date with descard_xxx #142

Closed
ysorigin opened this Issue Nov 28, 2009 · 1 comment

2 participants

@ysorigin

When I added :discard_month or :discard_day, builder also generate html hidden field for them:

<%= form.input :birth_year, :as => :date, :start_year => 1950, :discard_month => true, :discard_day => true, :input_html => {:name => "birth_year", :name => "birth_year",:class => "required"}%>

The generated HTML code:

<input id="video_birth_year_2i" type="hidden" value="1" name="video[birth_year(2i)]"/>
<input id="video_birth_year_3i" type="hidden" value="1" name="video[birth_year(3i)]"/>

Then I can't add attr(birth_year(2i),birth_year(3i)) to model to make the submit successful..what should i do ?

The source code:
if options[:"discard_#{input}"]
break if time_inputs.include?(input)

      hidden_value = datetime.respond_to?(input) ? datetime.send(input.to_sym) : datetime
      hidden_fields_capture << template.hidden_field_tag("#{@object_name}[#{field_name}]", (hidden_value || 1), :id => input_id)

What is the purpose for the hidden field?

@justinfrench
Owner

The hidden values are there because Rails expects the three-part date params to all be there. :discard_month means it will render a hidden input for the month "1" instead of a select box of options. This is also exactly what Rails does with date_select.

I don't think :as => :date should be your chosen input here. It looks like you just want to pass in a year, in which case a :select with a :collection of relevant years will do. Either way, this isn't a bug, so I'm closing it. Please discuss on the google group if need be.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.