lundi 9 septembre 2019

Is there a way to get checkbox's checked value in array? [React]

Checkbox generated based on data

This checkbox [ looks like toggle button] generated based on data. I want to get checked values in an array.

Code

{this.state.customersmsselect.map((e, key) => {
  $('#s').val(key);
  if(e.isactive == "ON"){
  return (
    <div key={key}>
      <div className="form-group col-md-8">
        <label className="col-md-4 control-label">{e.notificationtype}</label>
        <div className="col-md-4 smart-form">
          <label className="toggle">
            <input type="checkbox" id={"smscheckbox" + key} value={e.isactive + "," + e.smstemplateid} name={"checkbox-toggle"+e.smstemplateid} onChange={this.onChangeFavorite} defaultChecked />
            <i data-swchoff-text='OFF' data-swchon-text='ON' ></i>
        </label>
      </div>
    </div>
    <div style=>&nbsp;</div>
    </div>
  );

My onChange method

If click on that button then I will get, that button's name.

   onChangeFavorite(event) {
     if(!event.target.checked){
        console.log(event.target.name);
     }
   };

My customersmsselect array looks like

0: {smstemplateid: "1", notificationtype: "Invoice Details", isactive: "ON"}
1: {smstemplateid: "2", notificationtype: "Payment Thank-You", isactive: "ON"}
2: {smstemplateid: "3", notificationtype: "Daily Closing Balance", isactive: "OFF"}
3: {smstemplateid: "4", notificationtype: "Monthly Closing Balance", isactive: "ON"}

Problem

I want to get all the checked values in an array when I am click on the button.




Aucun commentaire:

Enregistrer un commentaire