Bootstrap Datepicker Default Value Simple_Form_For

Bootstrap datepicker default value simple_form_for

<%= f.input :payment_date, as: :string, input_html: { class: "datepicker", value: Time.now.strftime('%d-%m-%Y') } %>   

Another format to it is: (working with active admin gem)

f.input :date, as: :date_picker, :input_html => { :value => Date.today}

How can i put the bootstrap datepicker in my form and have the value in date parameter?

Use <%= f.text_field :name_of_the_date_column, :value=>Date.today.strftime('%m-%d-%Y'), :id =>"dp5" %>

To auto hide use this

$("#dt5").datepicker({
format: 'mm-dd-yyyy'
})
.on('changeDate', function(ev){
$('#dt5').datepicker('hide');
});

instead of

$("#dt5").datepicker();

Rails - Using Bootstrap datetimepicker form, date not arriving in controller?

First of all, this part:

return_string =
"#{@builder.text_field(attribute_name, text_field_options)}\n" +
"#{@builder.hidden_field(attribute_name, hidden_field_options)}\n"

is skipped since you redefine the variable next:

return_string = '<div id="datetimepicker1" class="input-append date form-horizontal">
<input data-format="MM/dd/yyyy" type="text">
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar">
</i>
</span>'

The text input with the appropriate attributes doesn't render so nothing is being posted when you submit.

Also, if you are going to combine these two values and render them, it will result to two elements with the same id (datepicker1).

Add datepicker with rails 3.2.11, simple_form and bootstrap

Make sure datepicker is called in your JavaScript (change datepicker class if it is different in your form):

$(function() {
$('input.datepicker').datepicker();
});

Also you can check
How do i write a cleaner date picker input for SimpleForm
or https://github.com/plataformatec/simple_form/issues/75#issuecomment-448362

Specifying data format in Rails for SimpleForm and Boostrap DateTime picker

Okay got it working like this:

.datetime.input-append
= f.input :mikor, :label => "Time", :wrapper => :append do
= f.input_field :mikor, :as => :string, "data-format" => "yyyy/MM/dd hh:mm:ss"
%span.add-on
%i{"data-date-icon" => "icon-calendar", "data-time-icon" => "icon-time"}

Looks like we don't need to put data-format inside input_html this way.



Related Topics



Leave a reply



Submit