[LiveComponent] Document how to use `extra_options` in the Ajax-powered autocomplete
| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | n/a |
| Issues | requested in https://github.com/symfony/ux/pull/1322#issuecomment-1986102279 |
| License | MIT |
Time spent on this PR has been sponsored by Commerce Weavers ♥️.
Thanks @jakubtobiasz ! I'll make some minor comments / suggestions tonight, but this is very welcome !
@smnandre I believe there're might be some places to be improved, as I'm not the best to write docs, especially if most of them have some kind of standarization :D. So I'm open for any comments 🙌🏻.
A more sensible point here: i'd really like to warn users those values will be "readable" from front... or are they encoded i don't remember what choice was made in the end ?
@jakubtobiasz Thanks for this PR.
In my use case, we need to overwrite the label.
I solved it with this Code, and i think this is useful for others as well.
Maybe you can add this to the PR? Otherwise i can add a PR after this is merged.
#[AsEntityAutocompleteField]
class FooAutocompleteField extends AbstractType
{
public function buildView(FormView $view, FormInterface $form, array $options): void
{
if(isset($options['extra_options']['label'])) {
$view->vars['label'] = $options['extra_options']['label'];
}
}
class FooFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('bar', FooAutocompleteField::class, ['extra_options' => ['label' => 'Overwritten Label']]);
}
...
}
@jakubtobiasz do you need some help here ?
@smnandre being honest, this PR just fell out of my head 😅; I'll try to finalize it this ASAP.
No hurry, and if i can help in any way please ask ;)
@smnandre Finally I've got some time (thanks to Commerce Weavers) to finish this PR. I've left comments unresolved, so feel free to resolve them once you decide a given issue is resolved.
I'll check later this week, but already a big thank you !
I've left comments unresolved, so feel free to resolve them once you decide a given issue is resolved.
I have no button for this (or i don't know where to find them) 😅
But all good for me, a big big thank you :)
Thank you Jacob.