javascript - Rails combined two form fields into one -
how combined day , time "start_time" variable (and "end_time") before submitting? js?
<%= form_for @task |f| %> <%= render 'shared/error_messages', object: f.object %> <div class="time_selectors"> <%= f.label :start_time %> <%= f.text_field :start_time, :class => 'datepicker' %> <select class="form-control time_dropdown" id="start_hour"> <option>select date</option> </select> <div class="clear_both"></div> <%= f.label :end_time %> <%= f.text_field :end_time, :class => 'datepicker' %> <select class="form-control time_dropdown" id="end_hour"> <option>select date</option> </select> </div> <div class="clear_both"></div> </div> <div class="clear_both"></div> <%= f.submit "create task", class: "btn btn-large btn-primary" %> </div> <% end %>
i have them combined in task model, , i'd prefer leave them combined if can.
my js right doesn't work. missing?
$('#new-task').submit ()-> valuestosubmit = $(this).serialize console.log('test') console.log(valuestosubmit) return false $('button').click ()-> console.log ('test2')
what this?
$('form').on 'submit', (event) -> event.preventdefault() start_time = '' start_time += $(@).find('input[name=start_day]').val() start_time += '_' start_time += $(@).find('input[name=start_hour]').val() $('<input/>', {type: 'hidden', name: 'start_time', value: start_time}).appendto($(@)) @submit()
(*the coffeescript version hasn't been tested - use working fiddle guide.)
Comments
Post a Comment