2

I am building a section of my application that allows a user to make selections of certain items through the use of checkboxes. My goal is to have an array in the component state (this.state.schoolsSelected) that is edited on click events to store all of the selected values onChange and then submit that array.

There are 5 checkbox section options that represent types of schools (elem, middle, high, etc.) and then each school is rendered with a checkbox individually. My eventual goal is to get all the values of all selected checkboxes.

I am having trouble handling the different scenarios with component state, and was hoping somebody else had addressed this issue before.

My current solution is to have each checkbox rendered with its "checked" property representing the group of schools as its checked state (i.e. this.state.isMiddleChecked, this.state.isHighChecked) . When I select a checkbox like "Select all Middle", all middle schools are selected.

return(
      <Col key={index} sm={3}>
        <Checkbox
          checked={this.state.isHighChecked}
          value={index}
          onChange={this.onChange}
        >{school.name}</Checkbox>
      </Col>
    )

However, there is no way for me to select any of the checkboxes individually because they rely on this group property.

Please let me know if you need any clarifications on what I am asking.

1
  • is this.onChange used anywhere else in the application? Is this binding the function to allow it to be clicked? Is this a function? Commented Jun 9, 2018 at 0:41

1 Answer 1

0

how about adding a new attribute (like id,class or any given name ), that you can select all your individually grouped checkboxes?

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

2 Comments

that's a comment, not an answer
I don't have the reputation required yet

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.