ux icon indicating copy to clipboard operation
ux copied to clipboard

[Autocomplete] Opt-out from auto updates if the root has a live id

Open 1ed opened this issue 2 years ago • 3 comments

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(),
                ],
            ]);
        };

        /// ...
    }

1ed avatar Apr 16 '23 17:04 1ed