Next.js: Form component for input type="checkbox" not working and type error
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 50/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- next.js, react, typescript
Direzione di ricerca
Inizia in templates/next/components/foo/Form.tsx intorno alle righe 164-165 e confronta il components/hours/Form.tsx generato. Esegui docker compose exec pwa pnpm next build e prova la checkbox onInvoice seguendo la riproduzione del tutorial. Il lavoro è completato quando la checkbox generata usa il comportamento checked appropriato e la build di Next.js non segnala più l’errore di tipo boolean.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
create-client version(s) affected: 0.10.0
Description
After generating an app in the pwa container derived from the standard distribution the onInvoice checkbox in the hours Form does not work and when running
docker compose exec pwa pnpm next build
i get the following type error:
./components/hours/Form.tsx values.onInvoice Type 'boolean | ""' is not assignable to type 'string | number | readonly string[] | undefined'.
This happens because templates/next/components/foo/Form.tsx for input type="checkbox" uses 164-165:
{{#compare type "!=" "dateTime" }}
value={values.{{name}} ?? ""}
At first sight is may seem strange that an input wiht type="checkbox" does not accept booleans. But if you correct the type passed to value= and test the input you will see that the checkbox never gets checked.
How to reproduce
Clone MetaClass' Tutorial Api Platform repository using git:
git clone https://github.com/metaclass-nl/tutorial-api-platform.git
check out branch chapter2-next
start the containers with
docker compose up
The api container should execute the data base migrations automatically. If not do:
docker compose exec php ./bin/console doctrine:migrations:migrate
To clear the database and execute the fixtures enter the following command:
docker compose exec php bin/console doctrine:fixtures:load
Follow the instructions from readme.md. or point your browser to the same branch on github
and follow the instructions.
The paragraph "Checking types" describes how to reprocude this error as well as serveral others for wich seperate issues exist/will be created.
Possible Solution
What helps is to replace in the generated code:
value={values.onInvoice ?? ""}
by
checked={values.onInvoice}
Then the checkbox should be checked if onInvoice is true.
I guess the template needs an other {{#compare type "=" "checkbox" }} to handle this case.
Additional Context
Api Platform version v3.1.3
typescript config see pnpm-lock.yaml and tsconfig.json
- Lingua principale
- TypeScript
- Stelle
- 376
- Fork
- 132
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di api-platform/create-client
-
[potential Security Alert] New `test-vue-app` script added in `@api-platform/client-generator@0.8.0` Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
api-platform/create-client#396 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 38/100
api-platform/create-client#397 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
api-platform/create-client#395 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
api-platform/create-client#394 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
api-platform/create-client#393 · 1 commento ·
Tutte le issue di api-platform/create-client
Issue simili
-
blocklist removal
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
MetaMask/eth-phishing-detect#296544 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
pastelsky/bundlephobia#1122 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100