Forms 如何设置可选日期字段?

Forms 如何设置可选日期字段?,forms,date,symfony,doctrine-orm,admin-generator,Forms,Date,Symfony,Doctrine Orm,Admin Generator,我需要在表单中显示带有日期选择器的可选日期字段。 但是,当我创建新记录时,它会自动填充“持久化”上的当前日期。 当我试图更改它(使其为空)时,我得到了错误:“无效日期”。 我需要的机会只能选择设置此字段。 它不是必填字段。你能告诉我我做错了什么吗 我的实体代码: class Entity { ... /** * @ORM\Column(type="date", nullable=true) */ private $birthday = null; ... } My generator.ym

我需要在表单中显示带有日期选择器的可选日期字段。 但是,当我创建新记录时,它会自动填充“持久化”上的当前日期。 当我试图更改它(使其为空)时,我得到了错误:“无效日期”。 我需要的机会只能选择设置此字段。 它不是必填字段。你能告诉我我做错了什么吗

我的实体代码:

class Entity {
...
/**
 * @ORM\Column(type="date", nullable=true)
 */
private $birthday = null;
...
}
My generator.yml:

birthday:
    formType:    s2a_date_picker

您的实体/项目中是否有任何验证程序文件或规则

您是否也尝试将表单选项(通过addFormOption键)“Required”设置为false

==编辑

我刚刚创建了以下示例应用程序:

generator: admingenerator.generator.doctrine
params:
    model: Application\CoreBundle\Entity\Account
    namespace_prefix: Application
    concurrency_lock: ~
    bundle_name: AdminBundle
    pk_requirement: ~
    fields:
        id:
            filterable: 1
        name:
            filterable: 1
        expirationDate:
            formType:    s2a_date_picker
    object_actions:
        delete: ~
    batch_actions:
        delete: ~
builders:
    list:
        params:
            title: List for AdminBundle
            display: ~
            filters: ~
            actions:
                new: ~
            object_actions:
                edit: ~
                delete: ~
    excel:
        params: ~
        filename: ~
        filetype: ~
    new:
        params:
            title: New object for AdminBundle
            display:
                - name
                - expirationDate
            actions:
                save: ~
                list: ~
    edit:
        params:
            title: "You're editing the object \"%object%\"|{ %object%: Account.name }|"
            display:
                - name
                - expirationDate
            actions:
                save: ~
                list: ~
    show:
        params:
            title: "You're viewing the object \"%object%\"|{ %object%: Account.name }|"
            display: ~
            actions:
                list: ~
                new: ~
    actions:
        params:
            object_actions:
                delete: ~
            batch_actions:
                delete: ~
使用此实体映射:

Application\CoreBundle\Entity\Account:
type: entity
table: null
id:
    id:
        type: integer
        id: true
        generator:
            strategy: AUTO
fields:
    name:
        type: string
        length: 255
    expirationDate:
        type: datetime
        nullable: true
lifecycleCallbacks: {  }
当然,以防万一,实体:

<?php

namespace Application\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Account
 */
class Account
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var \DateTime
     */
    private $expirationDate = null;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Account
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @param \DateTime $expirationDate
     * @return $this
     */
    public function setExpirationDate(\DateTime $expirationDate = null)
    {
        $this->expirationDate = $expirationDate;

        return $this;
    }

    /**
     * @return \DateTime
     */
    public function getExpirationDate()
    {
        return $this->expirationDate;
    }
}

就我个人而言,我不会使用试图扩展或替换Symfony遗留功能的库。这不值得。。。水也清澈如泥。