Skip to content

Commit

Permalink
Fix edit ageCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Nov 29, 2024
1 parent 91503aa commit 480aaa6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/Form/BookFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 3 additions & 6 deletions src/Twig/Components/InlineEditMultiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand All @@ -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!';
}
}
4 changes: 2 additions & 2 deletions templates/components/InlineEditMultiple.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{% if isEditing and is_granted('ROLE_ADMIN') %}
<form class="input-group">
<select
{{ field!='ageCategory'?'multiple' }}
multiple
class="form-select form-select-sm"
id="books_{{ field }}"
data-model="fieldValue{{ field=='ageCategory'?'Int' }}"
data-model="fieldValue"
{{ stimulus_controller('symfony/ux-autocomplete/autocomplete', {
url: path('app_autocomplete_group', {type: field}),
}) }}
Expand Down

0 comments on commit 480aaa6

Please sign in to comment.