I am using a Symfony form with a collection of Datetime entries. How can I remove the empty datetime entries from the collection when the form is submitted?
I have set delete_empty to true but it is not working. I am trying hard to follow the doc instructions (https://symfony.com/doc/current/reference/forms/types/collection.html#delete-empty) but I must be missing something somewhere. I have also tried the required option to false and empty_data to null. Should I write a callable that check if datetime is empty? If so how to check if a datetime is empty?
Here is my form builder code:
$form = $this->createFormBuilder($event)
->add('datetimes', CollectionType::class, [
'entry_type' => DateTimeType::class,
'entry_options' => [
'date_widget' => 'single_text',
'input' => 'string',
'time_widget' => 'single_text',
'html5' => false,
'required' => false,
'empty_data' => null,
],
'label' => false,
'allow_add' => true,
'allow_delete' => true,
'prototype' => false,
'delete_empty' => true
])
->add('submit', SubmitType::class)
->getForm();
Can someone tell me what I am missing or doing wrong here?