如何在 Symfony 上显示日期选择器?

我想根据 symfony 文档为我的日期类型字段设置一个日期选择器。自 packagist 'eternicode / bootstrap-datepicker' 以来,我已经安装了该软件包。我可以应用我定义的条件在我的 js 中输入日期字段(如日期格式),但仍然无法显示。我的 js 控制台中没有错误消息。我什至没有看到 datepikcer 组件..


我的表格类型:


   ->add('date_entree', DateType::class, [ 

                'widget' => 'single_text',

                          'html5' => false,

                          'attr' => ['class' => 'js-datepicker'],

                ])


My JS:


    $(document).on('ready', function() {

         $('.js-datepicker').datepicker({

              format: 'dd-mm-yyyy',

         });

     });

你对这个问题有什么想法吗?


ITMISS
浏览 156回答 1
1回答

慕容森

最后,这是我的解决方案:css:&nbsp;< link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.css" rel="stylesheet"/>JS&nbsp; &nbsp; &nbsp; &nbsp; <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.js"></script>&nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; $(document).ready(function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // you may need to change this code if you are not using Bootstrap Datepicker&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.js-datepicker').datepicker({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; format: 'yyyy-mm-dd'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; </script>表格类型&nbsp; &nbsp;->add('date_entree', DateType::class, [&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 'widget' => 'single_text',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'html5' => false,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'attr' => ['class' => 'js-datepicker'],&nbsp; &nbsp; &nbsp; &nbsp; ])希望对其他开发者有所帮助!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript