0

Please help me,

I want to disable my box input value when I active my checklist box...

<FormGroup check className="mb-3">
        <Label check htmlFor="partial_shipment">
          <Input
            type="checkbox"
            name="partial_shipment"
            id="partial_shipment"
            onChange={onChange}
          />{" "}
          Apakah Partial Shipment?
        </Label>
      </FormGroup>

After I checklist my check box, I want disable...my this box input :

<FormGroup>
            <Label htmlFor="total_kemasan">Total Kemasan</Label>
            <Input
              type="number"
              name="total_kemasan"
              id="total_kemasan"
              onChange={onChange}
            />
          </FormGroup>

what I must todo??? with REACT HOOKS

0

1 Answer 1

1

If you want to disable the checkbox when checked you can change the disabled prop of the input.

const [checkBoxValue, setCheckBoxvalue] = useState(false);

<FormGroup>
        <Label htmlFor="total_kemasan">Total Kemasan</Label>
        <Input
          type="number"
          name="total_kemasan"
          disabled = {checkBoxValue}
          id="total_kemasan"
          onChange={handleCheckBox}
        />
      </FormGroup>

On your onChange handler, you will get event.target.checked -

handleCheckBox = e => {
if(e.target.checked){
setCheckBoxValue(true);
}else{
setCheckBoxValue(false);
}

You can change the value of the state in the handler and disable the checkbox when it is checked.

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

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.