-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
[Autocomplete] Configurable results #2541
base: 2.x
Are you sure you want to change the base?
Conversation
… that extra options may be exposed for tom-select to use them
I'm not sure why I am getting failures related to "direct deprecation notices" on [LiveComponent] (see https://github.com/symfony/ux/actions/runs/13069237861/job/36467092283?pr=2541 and https://github.com/symfony/ux/actions/runs/13069237861/job/36467096825?pr=2541) when I didn't update this component nor anything related to |
/** | ||
* Returns the autocomplete result, usually the label as "text" and the value as "value". | ||
* May be used to expose extra options such as "disabled" so that tom-select's rendering may be customized. | ||
* | ||
* @param T $entity | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
/* public function getResult(object $entity): array; */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... i'm now pretty sure.
We have
- a
getLabel
method (equivalent to choice_label in Form options - a
getValue
method (equivalent to choice_value in Form options)
Instead of introducing a new method that englobes/replaces the previously existing one, i'd rather add a new method
/**
* @return array<string, string|null>|null
*/
public function getAttributes(object $entity): ?array
In your scenario, you could return ['disabled' => true] when you'd want to.
Wdyt ?
Thank you for the PR, this feature (and the effort to improve things passing by -- docblocks for static analysis)! Minor changes to match existing DX / wording in symfony/form, and maybe add one or two tests to check everything work if the method is not implemented, or does not override getValue/getText On an implementation level, you should probably do something like this in the formatResult method $attributes = [];
if (method_exists(.....
....
}
return [
...$attributes,
'value' => $autocompleter->getValue(),
'text' => $autocompleter->getText(),
]; |
…Interface::getResult() method until next major version
… attributes rather than allowing to override the result entirely
…merged with value and text
Thanks for your review. I like your idea of merging extra attributes into an array containing the text and the value. WDYT of the latest version of my branch? |
src/Autocomplete/tests/Fixtures/Autocompleter/CustomAttributesProductAutocompleter.php
Outdated
Show resolved
Hide resolved
Tiny details, then lets see the CI failures and LGTM :) Would you be ok (on another PR) to write a paragraph + example about this in the documentation ? I can help if you need / want. |
Ok everything should be fine now 👍🏻 Regarding the failing tests however,
However there is no Edit: I found the failing tests and I fixed them 🥳 |
No worries for writing a bit of documentation, could you just point me the place and the kind of doc you expect? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for me!
Nice PR and thank you @J-Ben87
TomSelect accepts by default an array of results, each item containing a "text" and a "value".
Therefore this bundle exposes results formatted like so.
However one may need to expose additional data such as a "disabled" state to customize TomSelect's rendering.
This PR aims to offer this possibility by letting
EntityAutocompleter
s drive the creation of the results array.