question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CheckBox with Form was not work

See original GitHub issue

Version

2.12.8

Environment

ubuntu14.04, react15.6.1

Reproduction link

Steps to reproduce

I’m first use <Checkbox> component to complete , and then use the <Form> component nested in the outer layer. that will show me a error:

`getFieldDecorator` will override `value`, so please don't set `value` directly and use `setFieldsValue` to set it.

Then i tyr put <CheckboxGroup> value to <FormItem> initialValue, it’s ok.

But next, i try to click some checkbox value,and then to click the check all checkbox, it;s not work.

What is expected?

can be work well

What is actually happening?

It’s work well when first click, but after to click some checkbox value, again to click check all is not work


After ckick some checkbox, try to click all check is not work I try to remove <Form> component, only one <CheckBox> component to work, it’s work well. so, i think that issue because of <Form> and <CheckBox> or my code issue?

ps: my english is too bad, sorry to bother you

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

117reactions
Faliszekcommented, Nov 7, 2017

I ran in to similar problem, when i was trying to send form with selected checkbox, because function validateFields expect to get value from field, but checkbox returned “checked”, solution to my problem was set in the fieldDecorator valuePropName as ‘checked’ like this.

<FormItem label="Name">
  {getFieldDecorator('name', {
      initialValue: some.value || '',
      valuePropName: 'checked'
          })(<Checkbox />)}
</FormItem>
20reactions
R-oncommented, Oct 30, 2018

I think the correct solution for setting initialValue for checkboxes is the following: You have to set two options:

  • valuePropName to “checked”
  • initialValue to “true” (or “false” but this is the default)
<Form.Item label="Dummylabel">
            {getFieldDecorator("name", {
              valuePropName: "checked",
              initialValue: true
            })(
              <Checkbox />
            )}
          </Form.Item>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Checkboxes not working - Stack Overflow
I'm trying to create a checklist but only the first checkbox is working. When I click on the other ones it checks the...
Read more >
Solved: HubSpot Community - Checkbox on form not working
Hello,. I have a checkbox on a form asking contacts if they are an employee of an certain organization or not, so obviously...
Read more >
<input type="checkbox"> - HTML: HyperText Markup Language
A checkbox allows you to select single values for submission in a form (or not). Try it. HTML Demo: <input type="checkbox">. Reset.
Read more >
Checkboxes not working in WPforms form | WordPress.org
Hello,. I'd like some help with my WPforms form on the page. It does not show the 'check' symbol when you click one...
Read more >
Form Checkbox | Components - BootstrapVue
For cross browser consistency, <b-form-checkbox-group> and ... Only basic/native HTML is supported in the html field (components will not work).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found