Skip to content

Commit

Permalink
Merge pull request #287 from sherlockode/fix/file-non-required
Browse files Browse the repository at this point in the history
Handle non required file
  • Loading branch information
Vowow authored May 5, 2023
2 parents dfe2ccb + 750d536 commit 6430d57
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Form/Type/AcbFileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->add('title', TextType::class, [
'label' => 'field_type.file.title',
'constraints' => [
'constraints' => !$options['required'] ? [] : [
new NotBlank(null, null, null, null, $options['validation_groups']),
],
])
Expand Down Expand Up @@ -97,8 +97,8 @@ public function updateForm(FormInterface $form, $data, $options)
$form
->add('file', FileType::class, array_merge([
'label' => 'field_type.file.file',
'required' => !$isFileUploaded,
], $isFileUploaded ? [] : [
'required' => !$isFileUploaded && $options['required'],
], $isFileUploaded || !$options['required'] ? [] : [
'constraints' => [
new NotBlank(null, null, null, null, $options['validation_groups']),
],
Expand All @@ -111,7 +111,9 @@ public function updateForm(FormInterface $form, $data, $options)
'label' => 'field_type.file.delete',
'required' => false,
]);
$form->add('src', HiddenType::class);
$form->add('src', HiddenType::class, [
'required' => $options['required'],
]);
}
}

Expand Down

0 comments on commit 6430d57

Please sign in to comment.