bootstrap-datepicker-rails将默认世纪视图设置为20世纪 [英] bootstrap-datepicker-rails set default century view to 20th century
问题描述
我正在使用
正如所看到的:通过设置数据:{date_start_view: decades}
:日期选择器默认为21世纪(2000年-2100年)。我希望它默认为20世纪,因为此日期选择器用于生日。
我确实通过 bootstrap-datepicker文档,但是我不清楚如何设置此行为。
为了显示上个世纪,您可以考虑文档中报告的以下选项:
defaultViewDate
最初打开日历时要查看的日期。日期的内部值将保留今天的默认值,但是当第一次打开日期选择器时,日历将打开为defaultViewDate而不是今天。如果不使用此选项,则今天仍然是默认的查看日期。
因此,您必须更改 defaultViewDate 从今天到上个世纪为止。
这意味着您必须更改代码中报告的以下部分:
数据:{提供: datepicker,date_start_view: decades}
至:
数据:{provide = datepicker,date_default_view_date = 01/01/1900,date_start_view = decades; }
在以下示例中:
< link rel = stylesheet href = https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css>
< script src = https://code.jquery.com/jquery-2.1.1.min.js>< / script>
< script src = https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js< / script>
< link rel = stylesheet href = https://rawgit.com/uxsolutions/bootstrap-datepicker/master/dist/css/bootstrap-datepicker.min.css>
< script src = https://rawgit.com/uxsolutions/bootstrap-datepicker/master/dist/js/bootstrap-datepicker.min.js< / script>
< div class = input-group date data-provide = datepicker data-date-default-view-date = 01/01/1900 data-date -start-view = decades>
< input type = text class = form-control>
< div class = input-group-addon>
< span class = glyphicon glyphicon-th< / span>
< / div>
< / div>
I am using the bootstrap-datepicker-rails gem and have the following code to show the date picker in my rails app:
<%= text_field_tag :birth_date, params[:birth_date], size: 9, data: {provide: 'datepicker', date_start_view: 'decades'}, class: 'form-control' %>
Here is what it shows when the user clicks on the date picker:
As one can see: by setting the option of data: {date_start_view: 'decades'}
: the date picker defaults to the 21st century (2000 - 2100). I want it to default to the 20th century because this date picker is for a birthdate.
I did look through the bootstrap-datepicker documentation but it was unclear to me how to set this behavior.
In order to show the last century decades you may consider the following option reported in the documentation:
defaultViewDate
Date to view when initially opening the calendar. The internal value of the date remains today as default, but when the datepicker is first opened the calendar will open to defaultViewDate rather than today. If this option is not used, "today" remains the default view date.
Therefore, you must change the defaultViewDate from today to a date belonging to the last century.
That means you must change the following section reported in your code :
data: {provide: 'datepicker', date_start_view: 'decades'}
to:
data: {provide="datepicker", date_default_view_date="01/01/1900", date_start_view="decades"}
In the following an example:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://rawgit.com/uxsolutions/bootstrap-datepicker/master/dist/css/bootstrap-datepicker.min.css">
<script src="https://rawgit.com/uxsolutions/bootstrap-datepicker/master/dist/js/bootstrap-datepicker.min.js"></script>
<div class="input-group date" data-provide="datepicker" data-date-default-view-date="01/01/1900" data-date-start-view="decades">
<input type="text" class="form-control">
<div class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</div>
</div>
这篇关于bootstrap-datepicker-rails将默认世纪视图设置为20世纪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!