dispatch action change value of hidden fields, persisted when submited

This commit is contained in:
Mathieu Jaumotte 2021-06-28 20:46:30 +02:00
parent 6f1209eaf5
commit b705c5910f
4 changed files with 50 additions and 34 deletions

View File

@ -112,41 +112,45 @@ class ActivityType extends AbstractType
}
if ($activityType->isVisible('socialIssues') && $accompanyingPeriod) {
$builder->add('socialIssues',
/*
HiddenType::class
*/
EntityType::class, [
'label' => $activityType->getLabel('socialIssues'),
'required' => $activityType->isRequired('socialIssues'),
'class' => SocialIssue::class,
'choice_label' => function (SocialIssue $socialIssue) {
return $this->socialIssueRender->renderString($socialIssue, []);
},
'multiple' => true,
'choices' => $accompanyingPeriod->getRecursiveSocialIssues(),
'expanded' => true,
]
);
$builder->add('socialIssues', HiddenType::class);
$builder->get('socialIssues')
->addModelTransformer(new CallbackTransformer(
function (iterable $socialIssuesAsIterable): string {
$socialIssueIds = [];
foreach ($socialIssuesAsIterable as $value) {
$socialIssueIds[] = $value->getId();
}
return implode(',', $socialIssueIds);
},
function (?string $socialIssuesAsString): array {
return array_map(
fn(string $id): ?SocialIssue => $this->om->getRepository(SocialIssue::class)->findOneBy(['id' => (int) $id]),
explode(',', $socialIssuesAsString)
);
}
))
;
}
if ($activityType->isVisible('socialActions') && $accompanyingPeriod) {
$builder->add('socialActions',
/*
HiddenType::class
*/
EntityType::class, [
'label' => $activityType->getLabel('socialActions'),
'required' => $activityType->isRequired('socialActions'),
'class' => SocialAction::class,
'choice_label' => function (SocialAction $socialAction) {
return $this->socialActionRender->renderString($socialAction, []);
},
'multiple' => true,
'choices' => $accompanyingPeriod->getRecursiveSocialActions(),
'expanded' => true,
]
);
$builder->add('socialActions', HiddenType::class);
$builder->get('socialActions')
->addModelTransformer(new CallbackTransformer(
function (iterable $socialActionsAsIterable): string {
$socialActionIds = [];
foreach ($socialActionsAsIterable as $value) {
$socialActionIds[] = $value->getId();
}
return implode(',', $socialActionIds);
},
function (?string $socialActionsAsString): array {
return array_map(
fn(string $id): ?SocialAction => $this->om->getRepository(SocialAction::class)->findOneBy(['id' => (int) $id]),
explode(',', $socialActionsAsString)
);
}
))
;
}
if ($activityType->isVisible('date')) {

View File

@ -69,6 +69,7 @@
{{ $t('activity.select_first_a_social_issue') }}
</span>
</div>
</div>

View File

@ -111,12 +111,24 @@ const store = createStore({
},
actions: {
addIssueSelected({ commit }, issue) {
let aSocialIssues = document.getElementById("chill_activitybundle_activity_socialIssues");
aSocialIssues.value = addIdToValue(aSocialIssues.value, issue.id);
commit('addIssueSelected', issue);
},
updateIssuesSelected({ commit }, payload) {
let aSocialIssues = document.getElementById("chill_activitybundle_activity_socialIssues");
aSocialIssues.value = '';
payload.forEach(item => {
aSocialIssues.value = addIdToValue(aSocialIssues.value, item.id);
});
commit('updateIssuesSelected', payload);
},
updateActionsSelected({ commit }, payload) {
let aSocialActions = document.getElementById("chill_activitybundle_activity_socialActions");
aSocialActions.value = '';
payload.forEach(item => {
aSocialActions.value = addIdToValue(aSocialActions.value, item.id);
});
commit('updateActionsSelected', payload);
},
addPersonsInvolved({ commit }, payload) {

View File

@ -23,7 +23,6 @@
{{ form_row(edit_form.scope) }}
{% endif %}
<!--
{%- if edit_form.socialIssues is defined -%}
{{ form_row(edit_form.socialIssues) }}
{% endif %}
@ -31,7 +30,7 @@
{%- if edit_form.socialActions is defined -%}
{{ form_row(edit_form.socialActions) }}
{% endif %}
-->
<div id="social-issues-acc"></div>
{%- if edit_form.reasons is defined -%}