Symfony日期表单字段不会采用read_only属性

I'm trying to get a Symfony Form date field to be read only. The syntax work for a text field but not for a date-select field.

This is the problem line:

->add('CreationDate', 'date', array('read_only' => true))

This is the full function:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $a=1;
    $builder
            ->add('Instructor_Lic','text',array('read_only' => true))
            ->add('First_Name')
            ->add('Last_Name')
            ->add('School_ID')
            ->add('Email')
            ->add('Status')
            ->add('Department')
            ->add('CreationDate', 'date', array('read_only' => true))
            ->add('EditDate', 'date', array('data' => new \DateTime()))
    ;
}

Any help would be appreciated.

You can use disabled attribute instead of read_only attribute

change

->add('CreationDate', 'date', array('read_only' => true))

to

->add('CreationDate', 'date', array('disabled' => true))

like accepted answer for this question

This is correct method to do it.

->add('CreationDate', 'date', array(
    'disabled' => true
)

Also, on newer symfony versions, instead of using form alias 'date', use:

use Symfony\Component\Form\Extension\Core\Type\DateType;
// ...

$builder->add('CreationDate', DateType::class, array(
    'disabled' => true,
));