From 77342fdeb7d31a7c266f93fcbfcbcdad7471e375 Mon Sep 17 00:00:00 2001 From: Mallory Dessaintes Date: Fri, 10 May 2024 14:39:25 +0200 Subject: [PATCH 1/3] Fix disable required constraint for freetext field --- Form/Type/DynamicFormType.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Form/Type/DynamicFormType.php b/Form/Type/DynamicFormType.php index 9e0e7361..4b8d76be 100644 --- a/Form/Type/DynamicFormType.php +++ b/Form/Type/DynamicFormType.php @@ -13,6 +13,7 @@ use Sulu\Bundle\FormBundle\Dynamic\Checksum; use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypePool; +use Sulu\Bundle\FormBundle\Dynamic\Types\FreeTextType; use Sulu\Bundle\FormBundle\Entity\Dynamic; use Sulu\Bundle\FormBundle\Entity\Form; use Sulu\Bundle\FormBundle\Exception\FormNotFoundException; @@ -113,12 +114,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) $options['attr']['placeholder'] = $placeholder; } + $formFieldType = $this->typePool->get($field->getType()); + // required - if ($field->getRequired()) { + if (!$formFieldType instanceof FreeTextType && $field->getRequired()) { $options['constraints'][] = new NotBlank(); } - $this->typePool->get($field->getType())->build($builder, $field, $locale, $options); + $formFieldType->build($builder, $field, $locale, $options); } // Add hidden locale. (de, en, ...) From 88d0ddd1c4f22c361d2baa9b65829096828f4681 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 6 Jun 2024 16:00:19 +0200 Subject: [PATCH 2/3] Apply suggestions from code review --- Form/Type/DynamicFormType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Form/Type/DynamicFormType.php b/Form/Type/DynamicFormType.php index 4b8d76be..7e2fe185 100644 --- a/Form/Type/DynamicFormType.php +++ b/Form/Type/DynamicFormType.php @@ -14,6 +14,7 @@ use Sulu\Bundle\FormBundle\Dynamic\Checksum; use Sulu\Bundle\FormBundle\Dynamic\FormFieldTypePool; use Sulu\Bundle\FormBundle\Dynamic\Types\FreeTextType; +use Sulu\Bundle\FormBundle\Dynamic\Types\HeadlineType; use Sulu\Bundle\FormBundle\Entity\Dynamic; use Sulu\Bundle\FormBundle\Entity\Form; use Sulu\Bundle\FormBundle\Exception\FormNotFoundException; From 1afd380ee2e8cbd2a8b88c4c77d6e5f7dbd38f56 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Thu, 6 Jun 2024 16:00:32 +0200 Subject: [PATCH 3/3] Update Form/Type/DynamicFormType.php --- Form/Type/DynamicFormType.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Form/Type/DynamicFormType.php b/Form/Type/DynamicFormType.php index 7e2fe185..d4567a3c 100644 --- a/Form/Type/DynamicFormType.php +++ b/Form/Type/DynamicFormType.php @@ -118,7 +118,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) $formFieldType = $this->typePool->get($field->getType()); // required - if (!$formFieldType instanceof FreeTextType && $field->getRequired()) { + if ( + !$formFieldType instanceof FreeTextType + && !$formFieldType instanceof HeadlineType + && $field->getRequired() + ) { $options['constraints'][] = new NotBlank(); }