Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to adapt TomSelect selects via setFormTypeOptions method #6643

Open
bytes-commerce opened this issue Dec 12, 2024 · 0 comments
Open

Allow to adapt TomSelect selects via setFormTypeOptions method #6643

bytes-commerce opened this issue Dec 12, 2024 · 0 comments

Comments

@bytes-commerce
Copy link
Contributor

Short description of what this feature will allow to do:
Right now there seems to be no possibility to modify the TomSelect behaviour trough PHP definitions, one must re-initialize TomSelect selects in a very complex way by injecting custom JS into a CRUD controller, then modifying TomSelect to your needs.

This is obviously a bit bad.

Example of how to use this feature

        yield AssociationField::new('groups', t('Group'))
            ->setColumns('col-sm-12')
            ->setFormTypeOptions([
                'attr' => [
                    'data-tomselect-options' => json_encode([
                        'placeholder' => 'Select an option',
                        'maxItems' => 1,
                        'allowEmptyOption' => true,
                    ])
                ],
            ])

This way, I could specify the form to allow one one selection, regardless of its Assignment. In the frontend, the user then would be able to select only one element.

This is useful when you have a complex relation between elements.

For example in my case, I have a Task, that is a ManyToMany relation to Groups, which is owned by a User (in a OneToMany relation).

So: Many Tasks have Many groups, which individually belong to one User.

In this case, EasyAdmin can only cover the first relation, with no possibility to have the second constraint in mind. By allowing a developer to form the select himself, it will be easier to cover complex relationship scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant