在我的Symfony 4项目中,我在datetime中使用了比例器插件。https://flatpickr.js.org/
因此,在我的formType中,我的日期字段是文本格式的:
->add('date', TextType::class, [
'label' => "Date de la mission",
'attr'=> [
'placeholder' => "Date de la mission"
],
])但在我的身体里,这是个约会时间。
那么,在提交之前如何解析它以给出一个日期时间呢?因为在视图中,这是一个字符串。我看过这个:https://flatpickr.js.org/instance-methods-properties-elements/#useful-static-methods
但我不明白我该怎么应用它..。
目前,我已经:
<script>
$("#ordre_mission_date").flatpickr({
enableTime: true,
dateFormat: "d/m/Y H:i",
locale: "fr",
time_24hr: true,
});
</script>有人能帮帮我吗?
发布于 2019-10-26 15:09:33
您需要更改您的date字段定义。不要使用TextType,而是使用DateTimeType
->add('date', DateTimeType::class, [
'label' => "Date de la mission",
'widget' => 'single_text',
'attr'=> [
'placeholder' => "Date de la mission"
],
])行'widget' => 'single_text'将DateTime字段呈现为单个<input type="text"/>,允许您使用插件。
https://stackoverflow.com/questions/58562896
复制相似问题