Topic: datetime_select narrow down minutes list

Is it possible to tell datetime_select to only have 00 and 30 in the minutes drop down list? If not, how can I provide such a list?

Re: datetime_select narrow down minutes list

You can disable the minute select for datetime_select then make your own using select.

<%= select :model, 'attribute(...)', ['00', '30'] %>

The 2nd parameter should match the name of the datetime_select so it ends up being passed in a very similar way.

Railscasts - Free Ruby on Rails Screencasts

Re: datetime_select narrow down minutes list

I have the following, but it does not work:

<p><label for="command_date_to_execute">Execution date</label><br/>
<%= datetime_select 'command', 'date_to_execute', :discard_minute => true  %>:
<%= select 'command', 'date_to_execute', ['00', '30'] %>
</p>

When I view the source in the browser 'select' produces the following:

[code="HTML"]
<select id="command_date_to_execute" name="command[date_to_execute]">
<option value="00">00</option>
<option value="30">30</option>
</select>
[/code]

But by looking at the pattern of the source code generated by 'datetime_select', shouldn't it generate something like:

[code="HTML"]
<select id="command_date_to_execute_5i" name="command[date_to_execute(5i)]">
<option value="00">00</option>
<option value="30">30</option>
</select>
[/code]

How do I get that 5i in the generated HTML?

Last edited by amiridis (2007-05-25 23:20:48)

Re: datetime_select narrow down minutes list

I'm not sure if this will work, but it's worth a try:

<%= select :command, 'date_to_execute(5i)', ['00', '30'] %>

Railscasts - Free Ruby on Rails Screencasts

Re: datetime_select narrow down minutes list

Suppose we want only values “00” and “30” to be displayed in minutes.
It can be done as follows:

= f.datetime_select(:leave_end, :start_year => 2010, :ampm => true, :default => 0.days.from_now.in_time_zone(@timezone), :discard_minute => true)
%span :
= f.select('req_sess_start(5i)', ['00', '30'])

But this way, the page throws exception of unknown variable req_sess_start(5i) if any validation fails on the page. But works, if all validations are met.
Following doesn't throws this exception:

= f.datetime_select(:req_sess_start, :start_year => 2010, :ampm => true, :default => 0.days.from_now.in_time_zone(@timezone), :minute_step => 30)

It works.