selected periods are not coming through in POST. Value not valid

This commit is contained in:
Julie Lenaerts 2022-03-28 16:46:39 +02:00
parent 7963076505
commit 818370f037
2 changed files with 26 additions and 45 deletions

View File

@ -99,38 +99,23 @@ class ReassignAccompanyingPeriodController extends AbstractController
$paginator->getCurrentPageFirstItemNumber() $paginator->getCurrentPageFirstItemNumber()
); );
// foreach ($periods as $period) { $assignPeriods = [];
// $periodIds[] = $period->getId();
// }
// $assignForm= $this->buildReassignForm($periods); foreach($periods as $period) {
$assignData = []; $assignPeriods[$period->getId()] = $period;
$assignForm = $this->createFormBuilder($assignData) }
->add('periods', ChoiceType::class, [
// 'data' => serialize($periods), $assignForm = $this->buildReassignForm($assignPeriods);
'choices' => $periods,
'multiple' => true,
'expanded' => true
])
->add('user', EntityType::class, [
'class' => User::class,
'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
'choice_label' => function (User $u) {
return $this->userRender->renderString($u, []);
},
'placeholder' => 'Choose a user to reassign to',
'multiple' => false,
'label' => 'User',
'required' => true,
])
->getForm();
$assignForm->handleRequest($request); $assignForm->handleRequest($request);
if ($assignForm->isSubmitted()) { if ($assignForm->isSubmitted()) {
$periods = $assignForm->get('periods')->getData(); $periods = $assignForm->get('periods')->getData();
$userAssign = $assignForm->get('user')->getData(); $userAssign = $assignForm->get('assignUser')->getData();
dump($periods);
dump($userAssign);
foreach($periods as $periodId) { foreach($periods as $periodId) {
$reassignPeriod = $this->courseRepository->find($periodId); $reassignPeriod = $this->courseRepository->find($periodId);
@ -188,30 +173,23 @@ class ReassignAccompanyingPeriodController extends AbstractController
'label' => 'User', 'label' => 'User',
'required' => false, 'required' => false,
]); ]);
// ->add('periods', HiddenType::class, [
// 'data' => serialize($periodIds),
// ]);
return $builder->getForm(); return $builder->getForm();
} }
private function buildReassignForm(array $periods): FormInterface private function buildReassignForm(array $periods): FormInterface
{ {
$defaultData = [ $defaultData = [];
'user' => [],
'periods' => $periods
];
$builder = $this->formFactory->createBuilder(FormType::class, $defaultData, ['csrf_protection' => false, ]); $builder = $this->formFactory->createBuilder(FormType::class, $defaultData, ['csrf_protection' => false, ]);
$builder $builder
->add('periods', ChoiceType::class, [ ->add('periods', ChoiceType::class, [
// 'data' => serialize($periods),
'choices' => $periods, 'choices' => $periods,
'multiple' => true, 'multiple' => true,
'expanded' => true 'expanded' => true
]) ])
->add('user', EntityType::class, [ ->add('assignUser', EntityType::class, [
'class' => User::class, 'class' => User::class,
'choices' => $this->userRepository->findByActive(['username' => 'ASC']), 'choices' => $this->userRepository->findByActive(['username' => 'ASC']),
'choice_label' => function (User $u) { 'choice_label' => function (User $u) {
@ -223,6 +201,8 @@ class ReassignAccompanyingPeriodController extends AbstractController
'required' => true, 'required' => true,
]); ]);
$builder->get('periods')->resetViewTransformers();
return $builder->getForm(); return $builder->getForm();
} }
} }

View File

@ -67,21 +67,22 @@
<h3>{{ 'Attribute parcours in this list to the following user,'|trans }}</h3> <h3>{{ 'Attribute parcours in this list to the following user,'|trans }}</h3>
<p><span class="badge rounded-pill bg-primary">{{ paginator.totalItems }}</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p> <p><span class="badge rounded-pill bg-primary">{{ paginator.totalItems }}</span> parcours à réassigner (calculé ce jour à {{ null|format_time('medium') }})</p>
<div class="row filter-box">
<div class="col-md-6">
{{ form_label(assignForm.user ) }}
{{ form_widget(assignForm.user, {'attr': {'class': 'select2'}}) }}
</div>
</div>
{{ form_start(assignForm) }} {{ form_start(assignForm) }}
<div class="row filter-box">
<div class="col-md-6">
{{ form_label(assignForm.assignUser ) }}
{{ form_widget(assignForm.assignUser, {'attr': {'class': 'select2'}}) }}
</div>
</div>
<div id="form_periods"> <div id="form_periods">
<div class="flex-table"> <div class="flex-table">
{# {{ dump(assignForm.periods.vars.choices) }} #}
{% for choice in assignForm.periods.vars.choices %} {% for choice in assignForm.periods.vars.choices %}
<div class="form_check"> <div class="form_check" style="display:flex; margin-bottom:1rem;">
<input id="form_periods_{{ choice.value }}" class="form-check-input" type="checkbox" <input id="form_periods_{{ choice.value }}" class="form-check-input" type="checkbox" style="margin-right: 1rem;"
name="form[periods][{{ choice.value }}]" value="{{ choice.data.id }}"> name="form[periods][{{ choice.value }}]" value="{{ choice.value }}">
<label class="form-check-label" for="form_periods_{{ choice.value }}"> <label class="form-check-label" for="form_periods_{{ choice.value }}" style="display: block; width: 100%;">
{% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': choice.data, {% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': choice.data,
'recordAction': m.period_actions(choice.data), 'itemMeta': m.period_meta(choice.data) } %} 'recordAction': m.period_actions(choice.data), 'itemMeta': m.period_meta(choice.data) } %}
</label> </label>