-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
[LiveComponent] [Autocomplete] Autocomplete with custom data endpoint not working in a live component #1879
Comments
You should start by setting a LiveProp with the data you want to use in your form (a TestFormStruct instance i guess): https://symfony.com/bundles/ux-live-component/current/index.html#forms Then, some first questions to maybe give you some ideas / leads #1844 Can you look in the DOM & your browser inspector what is happening ? |
Ok, I thought that was optional. I've added it, but unfortunately it hasn't changed anything yet.
When I click in the selection field, a request is sent to the endpoint to load the options. Then the options are displayed and when I select an option, the live component is re-rendered. A request is then sent to the live component and this then fails with a 422 and returns the HTML, which then contains the message “The selected choice is invalid.”. This is the payload that is sent to the endpoint to re-render the live component after I select an option: {"props":{"initialFormData":{"testField":null},"formName":"test_form","test_form":{"testField":"","save":null,"_token":"..."},"isValidated":false,"validatedFields":[],"@attributes":{"id":"live-3754781061-0"},"@checksum":"..."},"updated":{"test_form.testField":"1","validatedFields":["test_form.testField"]}}
No, the browser stops me with the message from my second screenshot, because the field is required.
Yes, as soon as I click in the field
Yes, this works, but I need a live form as I need dependent fields in my real case, like in this example.
Yes, the live form with hardcoded choices works I found out that I can work around the problem by setting
But I don't think that's a nice solution. I think the problem is that the options loaded via Ajax are missing in the ChoiceList of the form field. A special “choice_loader” was used for the Entity Autocomplete, which I think must also be done for the Ajax Autocomplete. But I haven't come up with a solution yet. |
Maybe try this ? https://github.com/symfony/ux/issues/391#issuecomment-2139592202` |
No, unfortunately that doesn't help. In my case, it's not about an entity autocomplete. My custom Ajax endpoint, which loads the options, sends a request to an external API. So it would also be bad to have to call the external API again in a custom “choice_loader” (because of rate limits). Or should I still do it with the |
I have a problem when I use an autocomplete field, which uses a custom endpoint, together with a live component. I have simplified my case and added the files below. The problem is that when I select something in the autocomplete field, the message “The selected choice is invalid.” appears:
If I then click on “Save”, a message appears that I should select an element from the list, even though I have selected one:
Versions:
This is my form type:
This is my
TestFormStruct
:This is the
autocomplete_url
action:This is my live component:
And this is the template of my live component:
The component is added to a page with this:
<twig:TestForm />
Does anyone have any idea what the problem is?
The text was updated successfully, but these errors were encountered: