ux
ux copied to clipboard
[Autocomplete] Opt-out from auto updates if the root has a live id
| Q | A |
|---|---|
| Bug fix? | yes |
| New feature? | no |
| Tickets | - |
| License | MIT |
When I have a form with dependent fields I can tell when a dependency changes
and if I use a custom data-live-id attribute which calculated based on the
dependencies the dynamic fields will re-render correctly and fixes the issue
with multi-select fields.
For example this seems to work well:
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('department', null, [
'autocomplete' => true,
])
;
$formModifier = function (FormInterface $form, Department $department = null) {
$members = $department ? $this->organizationMemberRepository->findByDepartment($department) : [];
$form->add('participatingMembers', null, [
'autocomplete' => true,
'choices' => $members,
'attr' => [
'data-live-id' => 'participating-members-'.$department?->getId(),
],
]);
};
/// ...
}