html - Custom form select for date in Rails -
i'm trying set custom date select in rails. rails provides form helper called date_select. (<%= f.date_select %> in practice)
however html gives is: (showing month brevity.)
<select id="event_starttime_2i" name="event[starttime(2i)]"> <option value="1">january</option> <option value="2">february</option> <option value="3">march</option> <option value="4">april</option> <option value="5">may</option> <option value="6">june</option> <option value="7">july</option> <option value="8">august</option> <option value="9">september</option> <option value="10">october</option> <option value="11">november</option> <option value="12" selected="selected">december</option> </select>
i want little smarter, however. want user offered dropdown allows them select dates "today" "week today" , not force them select "year"/"month"/"day" individually. main concern ability of rails submit custom "select" options "datetime" attributes. (the date_select helper sends 3 http parameters: starttime(1i), starttime(2i) , starttime(3i). activerecord must combine single date before updating row in database. i'm wanting 1 dropdown , concern.)
this kind of i'm going for:
<select> <option value="1"><%= date.today %> </option> <option value="2"><%= date.today + 1%></option> <option value="3"><%= date.today + 2%></option> <option value="4"><%= date.today + 3%></option> <option value="5"><%= date.today + 4%></option> <option value="6"><%= date.today + 5%></option> <option value="7"><%= date.today + 6%></option> </select>
the last code snippet won't run here. looks in practice:
<select> <option value="1">2016-12-27</option> <option value="2">2016-12-28</option> <option value="3">2016-12-29</option> <option value="4">2016-12-30</option> <option value="5">2016-12-31</option> <option value="6">2016-01-01</option> <option value="7">2016-01-02</option> </select>
how work? (persist on submit datetime attribute of model)
if can rely on javascript suggest using bootstrap-datepicker-rails. can find excellent demo here. it's highly customizable , installation straightforward.
Comments
Post a Comment