Stefan Schuchlenz
Stefan Schuchlenz

Reputation: 117

Strip undesired values from Rails' time_select()

Can anybody point me to a solution for stripping out undesired values from a Ruby on Rails time_select?

Basically, time_select shows all hours from 00 to 24, but in my app I need to prevent users from choosing hours before 08 and after 16 directly in the SELECT tag and there does not seem to be a corresponding option I can pass to time_select.

Upvotes: 2

Views: 366

Answers (2)

user740584
user740584

Reputation:

select_time(my_time, start_hour: 8, end_hour: 16)

Upvotes: 0

Pavan
Pavan

Reputation: 33542

You could use select_time or select_hour.

select_time(my_time, start_hour: 8, end_hour: 16) # Generates a time select field with hours that range from 8 to 16

select_hour(my_time, start_hour: 8, end_hour: 16) # Generates a time select field with hours that range from 8 to 16

So that restricting the user to select time in between 8 and 16.

Upvotes: 2

Related Questions