Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Update Symfony 4 to 5 DatetimeType validation error [duplicate]

$
0
0

I have this Symfony 4.3.11 API rest application :

Here is my post request body:

{
    "publicationDate": "2019-03-13"
}

Entity :

   /**
     * @var \DateTimeImmutable
     *
     * @ORM\Column(type="datetime_immutable")
     *
     * @Assert\NotBlank(message="required.field")
     * @Assert\Date(message="invalid.date")
     */
    private $publicationDate;

MyEntityType :

    $builder
       ->add('publicationDate', DateTimeType::class, [
            'input'           => 'datetime_immutable',
            'widget'          => 'single_text',
            'format'          => 'yyyy-MM-dd',
            'invalid_message' => 'invalid.date',
        ]);

The Post Submit data looks like :

object(App\Entity\MyEntity)[3996]
  private 'id' => null
  private 'publicationDate' => 
    object(DateTimeImmutable)[5718]
      public 'date' => string '2019-03-13 00:00:00.000000' (length=26)
      public 'timezone_type' => int 3
      public 'timezone' => string 'Europe/Paris' (length=12)

And this works fine.

But now, I've a basic Symfony 5.0.5 app with the same Entity. The form type is slightly different (the html5 option should be disabled) :

MyEntityType :

    $builder
       ->add('publicationDate', DateTimeType::class, [
            'input'           => 'datetime_immutable',
            'html5'           => false,
            'widget'          => 'single_text',
            'format'          => 'yyyy-MM-dd',
            'invalid_message' => 'invalid.date',
        ]);

The Post Submit data is exactly the same as above.

But when submitting, I've a validation error :

array (size=1)
  'publicationDate' => 
    array (size=1)
      0 => string 'This value should be of type string.'

Has anything changed in datetimetype between S4 and S5 ?


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>