1

Hello im trying to fill the Checkbox value with my state but it dont accept it.

The Checkbox Code:

<Form.Item label="Aktiv" >
    <Checkbox value={this.state.selectedRecord.active} />
</Form.Item>

Value of the state selectedRecord: enter image description here

2 Answers 2

5

try changing it to this.

<Checkbox checked={this.state.selectedRecord.active} />

Sign up to request clarification or add additional context in comments.

Comments

0

The AntD documentation here says to the question "Why not work in Form.Item?":

"Form.Item default bind value to value property, but Checkbox value property is checked. You can use valuePropName to change bind property."

So, you could try:

<Form.Item label="Aktiv" valuePropName="checked">
    <Checkbox value={this.state.selectedRecord.active} />
</Form.Item>

But it still doesn't work for me for some reason, so I used something like this:

<Form.Item label="Aktiv" name="aktiv">
    <Checkbox />
</Form.Item>

and this to set it checked or unchecked:

form.setFieldValue('aktiv', {this.state.selectedRecord.active});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.