简体   繁体   中英

date_select to current and past month select only in rails

in form i used date_select but by default it adds all month of year. i am able to restrict year to current and past year but i am not able to restrict month. i want when user select 2020 they won't see September in there drop-down.

here is my current code-

<div class="field medium-4 columns">
   <%= form.label :attendance_month %>
   <%= form.date_select :attendance_month, { :discard_day => true, :discard_month => false, :discard_year => false, :end_year => Time.now.year },:class => 'month-and-year' %>
</div>

Using date_select you have only the option of restricting the year but not the month and day.

Either you can add model validation on date and raise error. Or you can use jQuery Date Picker plugin and set minDate and maxDate options to restrict the date range.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM