douruduan8812 2019-01-07 10:25
浏览 7
已采纳

如何在Doctrine中使用Symfony Widgets

I want to use this widget in my datafield:

'widget' => 'single_text',

but i can't insert in my code:

 /**
 * @var string
 *
 * @ORM\Column(name="purchasedate", type="date")
 * @Assert\Range(
 *      min = "2019-01-14",
 *      max = "2019-04-14"
 * )
 * 
 * 
 * @Serializer\SerializedName("purchasedate")
 * @Serializer\Expose()
 * 
 */

private $purchasedate;

How the field is suppose to be

How it's now

How i'm building the form :

  <div class="form-group col-12">
        {{ form_widget(form.user.purchasedate, {'attr': {'class': 'form-control required',
        'placeholder': 'Date d’achat (JJ/MM/AAAA)*', 'maxlength': 13}})}}
        {% if form_errors(form.user.purchasedate) %}<span class="error-form">{{
            form_errors(form.user.purchasedate) }}</span>{% endif %}
    </div>

Controller PatricipationType

  • 写回答

1条回答 默认 最新

  • dqb14659 2019-01-07 11:34
    关注

    You must put it in the formType like this:

    $builder->add('purchasedate', DateType::class, array(
      'widget' => 'single_text',
      'html5' => false,
    ));
    

    In your case $purchasedate is a property of User class, so it should be added to UserType form type class.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 MddBootstrapInitialize2失败
  • ¥15 LCD Flicker
  • ¥15 Spring MVC项目,访问不到相应的控制器方法
  • ¥15 esp32在micropython环境下使用ssl/tls连接mqtt服务器出现以下报错Connected on 192.168.154.223发生意外错误: 5无法连接到 MQTT 代理,如何解决?
  • ¥15 关于#genesiscsheel#的问题,如何解决?
  • ¥15 Android aidl for hal
  • ¥15 STM32CubeIDE下载程序报错
  • ¥15 微信好友如何转变为会员系统?(相关搜索:小程序)