views:

256

answers:

4

I am using the Rails helper datetime_select in one of my forms. I currently have a requirement to change the dropdowns for day, year, hour, and minute to be textboxes with validation. Is there a way I can specify that I want textboxes for these fields? Or possibly a different helper that will do what I need?

here is my usage:

datetime_select(:campaign, :start_date, :order => [:day, :month, :year, :hour, :minute])
A: 

I just found this plugin.

Hope it helps!

j.
this is close, but it makes all fields into text fields. I would like to keep the month field as a dropdown. see the yahoo registration for an example.
Russ Bradberry
A: 

I don't have a solution at hand but I stumpled upon a recent Railscase episode about calenders.

Maybe there is another plugin that serves your needs (or where you can adopt parts of the sourcecode).

Besides, you can always choose not to use a Rails helper for those fields.

duddle
+1  A: 

how about rolling your own simple helper, like

def datetime_text_fields(object_name, method)
  html = text_field_tag("#{object_name}[#{method}(3i)]", Date.today.day.to_s, :length => 2)
  html << select_month(Date.today, :field_name => "#{object_name}[#{method}(2i)]")
  html << text_field_tag("#{object_name}[#{method}(1i)]", Date.today.year.to_s, :length => 4)
  html << " "
  html << text_field_tag("#{object_name}[#{method}(4i)]", Time.now.hour.to_s, :length => 2)
  html << ":"
  html << text_field_tag("#{object_name}[#{method}(5i)]", Time.now.min.to_s, :length => 2)
end

Feel free to add more formatting stuff/separators etc. but it basically returns to correct field names for rails to be identified as DateTime. Rails expects fields named like date(1i), 1i = year, 2i = month etc.

Honestly I didn't test it or anything, but the output in console looked pretty convincing ;)

lwe
A: 

Why not roll your own, just name the input fields in the same exact way that the date picker helper does, and you get all the back-end benefits while rolling a custom front-end. Or use the :order to have your date picker give the month selection, and use some javascript magic for the other input.

You can use a jquery datepicker and populate hidden fields with the same naming convention as the rails datepicker.

Dmitriy Likhten