Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit minutes list on datetime_select

I am using Rails on a web application.
I would like to know if its possible to tell datetime_select to only have two options in the minutes drop down list? Options 00 and 30.

I have the below code:

<p><label for="command_date_to_execute">Date to Run</label><br/>
<%= datetime_select 'command', 'date_to_run', :discard_minute => true  %>:
<%= select 'command', 'date_to_run', ['00', '30'] %>
</p>

The browser source produces:

<select id="command_date_to_run" name="command[date_to_run]">
<option value="00">00</option>
<option value="30">30</option>
</select>

But I really need is below (with the 5i in the generated 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>

Please help


1 Answers

If you only want values 00 and 30 to be displayed for the minutes, you can do the below:

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

This might get exceptions on the page validation due to the (possibly) unknown variable req_sess_start(5i). Will work if validation is met.

The below would work better though as will not throw the exception.

= f.datetime_select(:req_sess_start, :start_year => 2011, :ampm => true, :default => 0.days.from_now.in_time_zone(@timezone), :minute_step => 30)
like image 105
Craig Taub Avatar answered Sep 03 '25 22:09

Craig Taub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!