sonata_type_datetime_picker 初始日期
sonata_type_datetime_picker Initial date
现在,当日期输入为空并且我将触发日期选择器时,它会给我当前的日期时间。我想更改此配置以获取当前日期但时间 00:00:00。我不知道如何得到这个。有什么想法吗?
我知道我在创建日期选择器时有这个选项:
"action", "attr", "auto_initialize", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "data", "data_class", "date_format", "date_widget", "datepicker_use_button", "days", "disabled", "dp_days_of_week_disabled", "dp_default_date", "dp_disabled_dates", "dp_enabled_dates", "dp_icons", "dp_language", "dp_max_date", "dp_min_date", "dp_minute_stepping", "dp_pick_time", "dp_show_today", "dp_side_by_side", "dp_use_current", "dp_use_minutes", "dp_use_seconds", "dp_use_strict", "empty_data", "empty_value", "error_bubbling", "error_mapping", "extra_fields_message", "format", "horizontal_input_wrapper_class", "horizontal_label_class", "horizontal_label_offset_class", "hours", "inherit_data", "input", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_render", "mapped", "max_length", "method", "minutes", "model_timezone", "months", "pattern", "post_max_size_message", "property_path", "read_only", "required", "seconds", "sonata_admin", "sonata_field_description", "sonata_help", "time_widget", "translation_domain", "trim", "validation_groups", "view_timezone", "virtual", "widget", "with_minutes", "with_seconds", "years"
我尝试使用 "dp_default_date",但它会在页面刷新时填充空白输入。 "hours" 和 "minutes" 不起作用。
然后您可以通过 vendor\sonata-project\core-bundle\Resources\views\Form 中的奏鸣曲覆盖日期时间选择器用户,您会发现 datepicker.html.twig 所以复制文件并将其放在 \app\Resources\views\Form 下,并将此脚本添加到块 sonata_type_date_picker_widget:
{% block sonata_type_date_picker_widget %}
{% spaceless %}
{% if datepicker_use_button %}
<div class='input-group date datepicker' id='{{ id }}' data-date-autoclose="true" data-date-format="dd/mm/yyyy">
{% else %}
{% set attr = attr|merge({'data-date-format': moment_format}) %}
{% endif %}
{{ block('date_widget') }}
{% if datepicker_use_button %}
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
{% endif %}
//Script to add//
<script type="text/javascript">
(function ($) {
$.fn.datepicker.dates['fr'] = {
days: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
daysShort: ["Dim.", "Lun.", "Mar.", "Mer.", "Jeu.", "Ven.", "Sam.", "Dim."],
daysMin: ["D", "L", "Ma", "Me", "J", "V", "S", "D"],
months: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
monthsShort: ["Janv.", "Févr.", "Mars", "Avril", "Mai", "Juin", "Juil.", "Août", "Sept.", "Oct.", "Nov.", "Déc."],
today: "Aujourd'hui",
clear: "Effacer",
weekStart: 1,
format: "dd/mm/yyyy hh:mm:ss"
};
}(jQuery));
jQuery(function ($) {
$('#{{ id }}').datepicker({
language: 'fr',
format: "dd/mm/yyyy hh:mm:ss"
});
});
</script>
{% endspaceless %}
{% endblock sonata_type_date_picker_widget %}
我是这样固定初始日期的
->add('dateOfBirth', 'sonata_type_date_picker', array(
'label' => 'Birthdate',
'dp_default_date' => '01-1975',
'datepicker_use_button' => false,
))
此处提供选项列表
sonata-project/core-bundle/Form/Type/DateTimePickerType.php
和
sonata-project/core-bundle/Form/Type/BasePickerType.php
现在,当日期输入为空并且我将触发日期选择器时,它会给我当前的日期时间。我想更改此配置以获取当前日期但时间 00:00:00。我不知道如何得到这个。有什么想法吗?
我知道我在创建日期选择器时有这个选项:
"action", "attr", "auto_initialize", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "data", "data_class", "date_format", "date_widget", "datepicker_use_button", "days", "disabled", "dp_days_of_week_disabled", "dp_default_date", "dp_disabled_dates", "dp_enabled_dates", "dp_icons", "dp_language", "dp_max_date", "dp_min_date", "dp_minute_stepping", "dp_pick_time", "dp_show_today", "dp_side_by_side", "dp_use_current", "dp_use_minutes", "dp_use_seconds", "dp_use_strict", "empty_data", "empty_value", "error_bubbling", "error_mapping", "extra_fields_message", "format", "horizontal_input_wrapper_class", "horizontal_label_class", "horizontal_label_offset_class", "hours", "inherit_data", "input", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_render", "mapped", "max_length", "method", "minutes", "model_timezone", "months", "pattern", "post_max_size_message", "property_path", "read_only", "required", "seconds", "sonata_admin", "sonata_field_description", "sonata_help", "time_widget", "translation_domain", "trim", "validation_groups", "view_timezone", "virtual", "widget", "with_minutes", "with_seconds", "years"
我尝试使用 "dp_default_date",但它会在页面刷新时填充空白输入。 "hours" 和 "minutes" 不起作用。
然后您可以通过 vendor\sonata-project\core-bundle\Resources\views\Form 中的奏鸣曲覆盖日期时间选择器用户,您会发现 datepicker.html.twig 所以复制文件并将其放在 \app\Resources\views\Form 下,并将此脚本添加到块 sonata_type_date_picker_widget:
{% block sonata_type_date_picker_widget %}
{% spaceless %}
{% if datepicker_use_button %}
<div class='input-group date datepicker' id='{{ id }}' data-date-autoclose="true" data-date-format="dd/mm/yyyy">
{% else %}
{% set attr = attr|merge({'data-date-format': moment_format}) %}
{% endif %}
{{ block('date_widget') }}
{% if datepicker_use_button %}
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
{% endif %}
//Script to add//
<script type="text/javascript">
(function ($) {
$.fn.datepicker.dates['fr'] = {
days: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
daysShort: ["Dim.", "Lun.", "Mar.", "Mer.", "Jeu.", "Ven.", "Sam.", "Dim."],
daysMin: ["D", "L", "Ma", "Me", "J", "V", "S", "D"],
months: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
monthsShort: ["Janv.", "Févr.", "Mars", "Avril", "Mai", "Juin", "Juil.", "Août", "Sept.", "Oct.", "Nov.", "Déc."],
today: "Aujourd'hui",
clear: "Effacer",
weekStart: 1,
format: "dd/mm/yyyy hh:mm:ss"
};
}(jQuery));
jQuery(function ($) {
$('#{{ id }}').datepicker({
language: 'fr',
format: "dd/mm/yyyy hh:mm:ss"
});
});
</script>
{% endspaceless %}
{% endblock sonata_type_date_picker_widget %}
我是这样固定初始日期的
->add('dateOfBirth', 'sonata_type_date_picker', array(
'label' => 'Birthdate',
'dp_default_date' => '01-1975',
'datepicker_use_button' => false,
))
此处提供选项列表
sonata-project/core-bundle/Form/Type/DateTimePickerType.php
和
sonata-project/core-bundle/Form/Type/BasePickerType.php