Remove time and time separator in date list with simple rails

How can I remove the datetime separator and the time separator into a date, select create by gem called simple_form?

I think I should override the method initializethat uses simple_form to create a date picker or pass hash parameters in the input form of my form. But that does not work.

I am trying something like this:

f.input :as => :date, options:{:date_separator => '', :time_separator => ''}

Thanks help me

+4
source share
4 answers

You must make this change to make it work:

f.input :your_attribute, as: :date, date_separator: '', time_separator: ''
# or
f.input :your_attribute, as: :date, date_separator: '<span>:</span>'

These 2 should work.

+3
source

You cannot do this just with simple_form.

.

protected

def process_business_hour(params)
    params[:business_hour] = "#{params[:"business_hour(4i)"].to_i}:#{params[:"business_hour(5i)"].to_i}"
    return params
end

, - ( simple_form), , .


.

<%= f.date_select 'business_hour_mon_start', {minute_step: 5}, class: "timeselect timeselect_mon", onChange: "javascript:selectBusinessHour(this.value)" %>~
<%= f.time_select 'business_hour_mon_end', {minute_step: 5, ignore_date: :true}, class: "timeselect timeselect_mon", onChange: "javascript:selectBusinessHour(this.value)" %>

...

http://i.stack.imgur.com/5Z0ur.png

.

, .

<select id="parkinglot_business_hour_mon_start_1i" name="parkinglot[business_hour_mon_start(1i)]" onchange="javascript:selectBusinessHour(this.value)">

. (1i)

0

, 10 .

.


jQuery datepicker, _.

http://oi58.tinypic.com/2d1mps2.jpg

.

http://jqueryui.com/datepicker/

jQuery datepicker .

<input type="text" id="date_start" class="form-control" value="<%= 1.month.ago.to_date %>">

<script>
$(function() {
  $( "#date_start" ).datepicker({
    dateFormat: "yy-mm-dd",
    defaultDate: "-1w -1d",
    changeMonth: true,
    maxDate: "-1",
    onClose: function( selectedDate ) {
      $( "#date_start" ).datepicker( "option", selectedDate );
    }
  });
});
</script>

, .

simple_form jog.

0

This fix is ​​not perfect, but works:

<script>
    var el = $("#mydiv");
    el.html(el.html().replace("—", ""));
    el.html(el.html().replace(":", ""));
</script>
0
source

Source: https://habr.com/ru/post/1544564/


All Articles