Next.js: Form component for input type="checkbox" not working and type error
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 50/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- next.js, react, typescript
Línea de trabajo
Comienza en templates/next/components/foo/Form.tsx alrededor de las líneas 164-165 y compara el components/hours/Form.tsx generado. Ejecuta docker compose exec pwa pnpm next build y prueba el checkbox onInvoice siguiendo la reproducción del tutorial. Se considera terminado cuando el checkbox generado usa el comportamiento checked apropiado y la compilación de Next.js ya no informa del error de tipo boolean.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 376
- Forks
- 132
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de api-platform/create-client
-
[potential Security Alert] New `test-vue-app` script added in `@api-platform/[email protected]`Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
api-platform/create-client#396 ·
-
[potential Security Alert] New `test-nuxt-app` script added in `@api-platform/[email protected]`Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
api-platform/create-client#397 ·
-
[potential Security Alert] New `test-next-app` script added in `@api-platform/[email protected]`Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
api-platform/create-client#395 ·
-
[potential Security Alert] New `test-react-app` script added in `@api-platform/[email protected]`Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
api-platform/create-client#394 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
api-platform/create-client#393 · 1 comentario ·
Todos los issues de api-platform/create-client
Issues similares
-
Resources: New palettes of MacaoAbiertoresources
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
railmapgen/rmg-palette#2445 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
danielmiessler/LifeOS#2242 ·
Los mantenedores suelen responder en 5 días
-
good first issue hacktoberfest help wanted translation
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
callstackincubator/appduct#129 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100