问题
How I can remove datetime separator and time separator in date select create by gem called simple_form ?
I think I must override initialize
method that simple_form use to create date select or pass hash options in input of my form. But it doesn't work.
I try something like this :
f.input :as => :date, options:{:date_separator => '', :time_separator => ''}
Thanks to help me
回答1:
You have to 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.
回答2:
You cant make it with simple_form only.
I recommend to process in controller.
protected
def process_business_hour(params)
params[:business_hour] = "#{params[:"business_hour(4i)"].to_i}:#{params[:"business_hour(5i)"].to_i}"
return params
end
Its really mess job, but if any other great method(only using simple_form), please let me know.
updated.
<%= 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)" %>
this method can..
http://i.stack.imgur.com/5Z0ur.png
check above image..
if is not enough, you can break apart like this.
<select id="parkinglot_business_hour_mon_start_1i" name="parkinglot[business_hour_mon_start(1i)]" onchange="javascript:selectBusinessHour(this.value)">
see (1i)
回答3:
Upload another answer because I dont hove 10 or more reputation.
so I cant add image or more than two links..
and my last recommendation is mixing jQuery datepicker, not simple_form only.
http://oi58.tinypic.com/2d1mps2.jpg
check above image..
http://jqueryui.com/datepicker/
jQuery datepicker is well documented and easy to implement.
<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>
sorry for this answer is not a direct solution.
customizing simple_form is always very annoying jog.
回答4:
This is a fix not ideal but works:
<script>
var el = $("#mydiv");
el.html(el.html().replace("—", ""));
el.html(el.html().replace(":", ""));
</script>
来源:https://stackoverflow.com/questions/24217759/remove-datetime-and-time-separator-in-date-select-with-simple-form-rails