如何将引导程序日期选择器放入我的表单中并在日期参数中设置值? [英] How can i put the bootstrap datepicker in my form and have the value in date parameter?
问题描述
我正在使用 bootstrap-datepicker.js,它运行良好.
<div id="dp5" class="input-append date" data-date-format="dd-mm-yyyy" data-date="12-02-2012"><input class="span2" type="dp5" readonly="" value="12-02-2012" size="16"><span class="附加组件"><i class="icon-th"></i></span>
我想在这种类型的 rails 中以我的形式使用它
<%= simple_form_for(@customer) do |f|%><%= f.error_notification %><div class="form-inputs"><%= f.input :name %><%= f.input :email %><%= f.input :address %><%= f.input :phone %><%= f.input :Projects %><%= f.radio_button :status, 0, :checked =>true%>发布<%= f.radio_button :status, 1 %>取消发布<%= f.radio_button :status, 2 %>废纸篓
<div class="form-actions"><%= f.button :submit %>
<%结束%>
在这里我想把日期选择器放在我的表单中
`<%f.(datepicker)%>`
这样当我提交表单时,我会在参数日期中获得日期的值.当我在 datepicker 中单击日期时,它应该隐藏并且默认日期应该指向当前日期.我的 appication.js 包括
$(function(){$('#dp5').datepicker({格式:'mm-dd-yyyy'});$('#dp3').datepicker({格式:'mm-dd-yyyy'});});
Use <%= f.text_field :name_of_the_date_column, :value=>Date.today.strftime('%m-%d-%Y'), :id =>"dp5" %>
要自动隐藏使用这个
$("#dt5").datepicker({格式:'mm-dd-yyyy'}).on('changeDate', function(ev){$('#dt5').datepicker('隐藏');});
代替
$("#dt5").datepicker();
I am using bootstrap-datepicker.js and it is working fine.
<div class="well">
<div id="dp5" class="input-append date" data-date-format="dd-mm-yyyy" data-date="12-02-2012">
<input class="span2" type="dp5" readonly="" value="12-02-2012" size="16">
<span class="add-on">
<i class="icon-th"></i>
</span>
</div>
</div>
I want to use it in my form in rails which is of such type
<%= simple_form_for(@customer) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :email %>
<%= f.input :address %>
<%= f.input :phone %>
<%= f.input :Projects %>
<%= f.radio_button :status, 0, :checked => true%>Publish
<%= f.radio_button :status, 1 %>Unpublish
<%= f.radio_button :status, 2 %>Trash
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
Here i want to put the date picker inside my form as
`<%f.(datepicker)%>`
so that when i submit my form i get the value of date in the parameter date. When i click on date in datepicker it should hide and the default date should point to the current date. my appication.js includes
$(function(){
$('#dp5').datepicker({
format: 'mm-dd-yyyy'
});
$('#dp3').datepicker({
format: 'mm-dd-yyyy'
});
});
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();
这篇关于如何将引导程序日期选择器放入我的表单中并在日期参数中设置值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!