Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

SimpleFormIterator issue when editing resources

Aperta
#485 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Inizia dal repository di riproduzione collegato e dal suo file pwa/components/Admin.tsx, in particolare dalla trasformazione dirtyFix sull’elemento Edit. Riproduci il flusso di modifica di Author aggiungendo un Book tramite SimpleFormIterator e controlla l’array salvato alla ricerca di valori @id e @type vuoti. Il lavoro è completato quando il nuovo Book annidato può essere salvato senza l’errore “No resource associated to ""”.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

API Platform version(s) affected: 3.0.2 (also 2.6.8 with last Admin version)

Description
Since react-admin 4.4+, I am not able to dynamically create sub-elements when editing a resource. Let's say I have Book and Author resources, you can create books from the Author edit page thanks to an ArrayInput and a SimpleFormIterator. When I tried to add Books to an Author with the Author edit page, the following error occurred : No resource associated to "".

How to reproduce
Here is an example repo to reproduce my issue : https://github.com/gaspardphilibert/issue-api-platform-admin-simpleformiterator. To experience the bug, you can create an Author with one Book, then edit the Author and try to add another Book. You shouldn't be able to add the second Book.

The reason
Version 4.4.0 of react-admin fixes an issue (https://github.com/marmelab/react-admin/pull/8204) linked to SimpleFormIterator default values when adding a record. It seems that it takes the first array value and reset its fields to make a default value for new elements. Obviously, during the process an empty @id field is also injected. So, when I add a new value in my SimpleFormIterator and save the entity, it sends the array with an item with an empty string @id. Like this for example :

{
    "@context": "/contexts/Author",
    "@id": "/authors/1",
    "@type": "Author",
    "name": "Shakespeare",
    "books": [
        {
            "@id": "/books/1",
            "@type": "Books",
            "name": "Roméo et Juliette"
        },
        {
            "@id": "",
            "@type": "",
            "name": "Macbeth"
        }
    ],
    "id": "/authors/1"
}

Hence the No resource associated to "". error.

Possible Solution
I used the transform property (dirtyFix function in my example repo) on the Edit element to remove the empty @id and it worked well but I am wondering if it's the best solution (I am quite new in the API Platform world, maybe it could be solved at a lower level).

Thanks for your help !

Lingua principale
TypeScript
Stelle
516
Fork
134
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di api-platform/admin

Tutte le issue di api-platform/admin

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.