Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Next.js: Form component for input type="checkbox" not working and type error

Đang mở
#371 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
50/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Lĩnh vực
frontend, tooling

Hướng nghiên cứu

Bắt đầu trong templates/next/components/foo/Form.tsx, khoảng dòng 164-165, và so sánh với components/hours/Form.tsx được tạo. Chạy docker compose exec pwa pnpm next build và kiểm tra checkbox onInvoice theo bản tái hiện của tutorial. Hoàn tất khi checkbox được tạo sử dụng hành vi checked phù hợp và bản build Next.js không còn báo lỗi kiểu boolean.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
376
Fork
133
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của api-platform/create-client

Tất cả issue của api-platform/create-client

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.