From 480aaa6ba0fbd93e1834fb759a49b3cbc3755f49 Mon Sep 17 00:00:00 2001 From: Sergio Mendolia Date: Fri, 29 Nov 2024 14:42:59 +0100 Subject: [PATCH] Fix edit ageCategory --- src/Form/BookFilterType.php | 14 +++++++++----- src/Twig/Components/InlineEditMultiple.php | 9 +++------ templates/components/InlineEditMultiple.html.twig | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Form/BookFilterType.php b/src/Form/BookFilterType.php index fbf8c5c7..49076687 100644 --- a/src/Form/BookFilterType.php +++ b/src/Form/BookFilterType.php @@ -249,13 +249,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'choices' => User::AGE_CATEGORIES + ['filter.age.notset' => 'null'], 'required' => false, 'mapped' => false, - 'expanded' => true, + 'expanded' => false, 'label' => 'filter.age', - 'multiple' => true, - 'target_callback' => function (QueryBuilder $qb, array $readValue): void { - if (in_array('null', $readValue, true)) { + 'multiple' => false, + 'target_callback' => function (QueryBuilder $qb, ?string $readValue): void { + if ($readValue === null) { + return; + } + + if ($readValue === 'null') { $qb->andWhere('book.ageCategory is null'); - } elseif ($readValue !== []) { + } else { $qb->andWhere($qb->expr()->in('book.ageCategory', ':ageCategory')); $qb->setParameter('ageCategory', $readValue); } diff --git a/src/Twig/Components/InlineEditMultiple.php b/src/Twig/Components/InlineEditMultiple.php index b64c4ace..f3dc70a5 100644 --- a/src/Twig/Components/InlineEditMultiple.php +++ b/src/Twig/Components/InlineEditMultiple.php @@ -28,9 +28,6 @@ class InlineEditMultiple extends AbstractController #[LiveProp(writable: true)] public array $fieldValue; - #[LiveProp(writable: true)] - public ?int $fieldValueInt = null; - #[LiveProp()] public bool $isEditing = false; @@ -63,8 +60,8 @@ public function save(EntityManagerInterface $entityManager): void $book->setSerie(implode(',', $this->fieldValue)); break; case 'ageCategory': - $value = $this->fieldValueInt; - $book->setAgeCategory($value); + $value = reset($this->fieldValue); + $book->setAgeCategory((int) $value); break; default: @@ -76,6 +73,6 @@ public function save(EntityManagerInterface $entityManager): void $this->dispatchBrowserEvent('manager:flush'); $this->isEditing = false; - $this->flashMessage = ' book updated'; + $this->flashMessage = 'books updated!'; } } diff --git a/templates/components/InlineEditMultiple.html.twig b/templates/components/InlineEditMultiple.html.twig index dbdfb41f..f8c64ecb 100644 --- a/templates/components/InlineEditMultiple.html.twig +++ b/templates/components/InlineEditMultiple.html.twig @@ -2,10 +2,10 @@ {% if isEditing and is_granted('ROLE_ADMIN') %}