mercredi 15 novembre 2017

Uncheck checkbox in React pop up

I want to uncheck all the checkboxes everytime the popup shows. Have written a function for it which it getting called on click of the popup show button but the previously checked checkboxes are still remaining checked. In the popup i have ul with li's that are generated by mapping.

My function is:

clearList() {
    var list_items = document.getElementById("bucket-list").getElementsByTagName("li");
    for(var i=0; i<list_items.length; i++) {
      list_items[i].getElementsByTagName("input").checked = false;
    }
  }

Inside render function:

<ul id="bucket-list">
              {this.state.buckets.map(function (bucket, i) {
                return (
                <li key={i}>
                  <input
                    type="checkbox"
                    value={bucket.id}
                    refs="status_changed"
                    onChange={self.onCheckUncheck.bind(self, "status_changed")} />
                  <label>{bucket.name}</label>
                </li>
                )
              })}
              </ul>




Aucun commentaire:

Enregistrer un commentaire