Skip to content

Commit

Permalink
move value attribute from button to input type hidden #3381
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinx13 committed Dec 3, 2024
1 parent e8da737 commit 9c309aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/Controller/Back/SignalementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ public function viewSignalement(
}
}
$isClosedForMe = $isClosedForMe ?? Signalement::STATUS_CLOSED === $signalement->getStatut();
$clotureForm = $this->createForm(ClotureType::class);
$clotureForm = $this->createForm(type: ClotureType::class, options: [
'is_admin_territory' => $this->isGranted('ROLE_ADMIN_TERRITORY'),
'is_accepted' => $isAccepted,
'is_affected' => $isAffected,
]);
$clotureForm->handleRequest($request);
$eventParams = [];
if ($clotureForm->isSubmitted() && $clotureForm->isValid()) {
Expand Down
13 changes: 12 additions & 1 deletion src/Form/ClotureType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ class ClotureType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$clotureType = 'partner';
if ($options['is_admin_territory']) {
$clotureType = 'all';
if ($options['is_affected'] && $options['is_accepted']) {
$clotureType = 'partner';
}
}

$builder
->add('motif', EnumType::class, [
'class' => MotifCloture::class,
Expand All @@ -31,14 +39,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'class' => 'fr-hint-text',
],
])
->add('type', HiddenType::class);
->add('type', HiddenType::class, ['data' => $clotureType]);
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => null,
'allow_extra_fields' => true,
'is_admin_territory' => false,
'is_affected' => false,
'is_accepted' => false,
'attr' => [
'id' => 'cloture_form',
],
Expand Down
26 changes: 17 additions & 9 deletions templates/_partials/_modal_cloture.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
{{ form_label(clotureForm.motif) }}
{{ form_help(clotureForm.motif) }}
{{ form_widget(clotureForm.motif) }}
{{ form_widget(clotureForm.type) }}
<div class="fr-input-group fr-mt-2v">
<label for="cloture_suivi" class="fr-label required">Détails de la clôture</label>
<p class="fr-hint-text">Précisez le contexte et les raisons de la clôture <em>(10 caractères
Expand Down Expand Up @@ -66,23 +67,30 @@
{% if is_granted('ROLE_ADMIN_TERRITORY') %}
<li>
<button class="fr-btn fr-icon-check-line"
form="cloture_form" name="cloture[type]" value="all" type="submit" disabled>
Cloturer pour tous les partenaires
form="cloture_form"
type="submit"
disabled>
Clôturer pour tous les partenaires
</button>
</li>
{% if isAffected and isAccepted %}
<li>
<button class="fr-btn fr-icon-check-line" form="cloture_form"
name="cloture[type]" value="partner" type="submit" disabled>
Cloturer pour {{ app.user.partner ? app.user.partner.nom }}
<button class="fr-btn fr-icon-check-line"
form="cloture_form"
type="submit"
disabled>
Clôturer pour {{ app.user.partner ? app.user.partner.nom }}
</button>
</li>
{% endif %}
{% else %}
<li>
<button class="fr-btn fr-icon-check-line" form="cloture_form"
name="cloture[type]" value="partner" type="submit" disabled>
Cloturer pour {{ app.user.partner ? app.user.partner.nom }}
<button class="fr-btn fr-icon-check-line"
form="cloture_form"
value="partner"
type="submit"
disabled>
Clôturer pour {{ app.user.partner ? app.user.partner.nom }}
</button>
</li>
{% endif %}
Expand All @@ -97,4 +105,4 @@
</div>
</div>
</div>
</dialog>
</dialog>

0 comments on commit 9c309aa

Please sign in to comment.