api-platform / admin

A beautiful and fully-featured administration interface builder for hypermedia APIs
https://api-platform.com/docs/admin/
MIT License
480 stars 130 forks source link

Select input not fulfilled with default response data #505

Closed Syfele closed 1 year ago

Syfele commented 1 year ago

API Platform version(s) affected: x.y.z It is not about API Platform, it is about admin

Description
User have a ManyToOne relation with country, I can create and show user with country, but in edit form, select are empty by default, and I have error saying No route found for "GET http://localhost/api/[object%20Object]" (from "http://localhost:3000/") As in the picture below

How to reproduce
App.js :

<HydraAdmin layout={MyLayout} entrypoint={process.env.REACT_APP_API_ENTRYPOINT}>
<ResourceGuesser name="users" list={UsersList} show={UserShow} edit={EditUser} create={CreateUser}></ResourceGuesser>

CreateUser.js : ( WORKS FINE)

<CreateGuesser {...props}>
<InputGuesser label="Email Address" source="email" type="email" />
<InputGuesser source="firstname" />
<InputGuesser source="lastname" />
<ReferenceInput
        label="User country"
        source="country"
        reference="countries"
      >
        <SelectInput source="country" optionText="label" />
      </ReferenceInput>
</CreateGuesser

EditUser.js :

<InputGuesser label="Email Address" source="email" type="email" />
<InputGuesser source="firstname" />
<InputGuesser source="lastname" />
<ReferenceInput source="country" reference="countries">
      <SelectInput label="User country" optionText="label" />
</ReferenceInput>

In the edit page, email, firstname and lastname are fulfilled but not country and I have error message : ( WITH the list of countries in it )

Am I missing something ? or whats wrong please ? I have try React admin - Selecting a Foreign Key with no result, It doubling user country option in the select

Additional Context
Capture d’écran de 2023-05-26 14-08-35

Thanks for help

alanpoulain commented 1 year ago

Hello, have you read https://api-platform.com/docs/admin/handling-relations/?

Syfele commented 1 year ago

Hello, have you read https://api-platform.com/docs/admin/handling-relations/?

@alanpoulain : Thanks for replying
Yes I read it, If I'm not mistaken, that's what I m using My API return Hydra, thats why I should use ReferenceField> with , the example shonwing in the docs using instead of