Next.js: Form component for input type="checkbox" not working and type error
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 50/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- next.js, react, typescript
調査の方向性
templates/next/components/foo/Form.tsx の164〜165行目付近から始め、生成された components/hours/Form.tsx と比較します。docker compose exec pwa pnpm next build を実行し、チュートリアルの再現手順に従って onInvoice チェックボックスを操作します。生成されたチェックボックスが適切な checked の動作を使用し、Next.js のビルドで boolean 型エラーが報告されなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- TypeScript
- スター
- 376
- フォーク
- 132
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/create-client のほかの issue
-
[potential Security Alert] New `test-vue-app` script added in `@api-platform/[email protected]`オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/create-client#396 ·
-
[potential Security Alert] New `test-nuxt-app` script added in `@api-platform/[email protected]`オープン
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
api-platform/create-client#397 ·
-
[potential Security Alert] New `test-next-app` script added in `@api-platform/[email protected]`オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
api-platform/create-client#395 ·
-
[potential Security Alert] New `test-react-app` script added in `@api-platform/[email protected]`オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/create-client#394 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
api-platform/create-client#393 · コメント 1 件 ·
api-platform/create-client の issue をすべて見る
似ている issue
-
check:passed streams:add
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
Fission-AI/OpenSpec#1986 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
nestjs/docs.nestjs.com#3554 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
publicodes/publicodes#868 ·
-
namespace operations
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
EclipseFdn/open-vsx.org#13488 ·
メンテナーはふだん 2 日以内に返信