dimanche 15 mars 2020

How to display a checkbox boolean value in a data preview in React?

I'm trying to set up a checkbox in React so that it would display a boolean (true/false or checked/unchecked) in a data preview box. I couldn't make it work yet.

I guess my onChange event is not right (handleOnChangeAgreementCheckbox). How do I fix that?

Demo on codesandbox

Code

          <Input
            name="eligibleAge"
            type="checkbox"
            label="I agree"
            checked={this.state.active}
            value={this.state.checked}
            onChange={(e) => {
              this.handleOnChangeAgreementCheckbox({
                target: {
                  name: e.target.name,
                  value: e.target.checked,
                },
              });
            }}
          />

Desired Output in Data Preview:

    "eligibleAge": true

or

    "eligibleAge": "checked"

(Thanks! I'm new to React framework.)




Aucun commentaire:

Enregistrer un commentaire