1

So, I have this table with these checkboxes. When I click on "Add Entries" the right modal is being opened. When I click on "Done", the checkboxes should become unchecked without refreshing the page. Can you please advise me with a solution? enter image description here

class Home extends Component {
    selectedApps=[];
    selectedAppsObjArr=[];
       state={
        appList:[],
        isOpen:false,
        addedAppsArray:[],
       }

This is the function that it's content is the input checkbox

 chooseAppSelector=()=>
     {
        let appSelectorArray=[];
        for (let application of this.state.appList)
        {
        appSelectorArray.push(

            <tr>
            **<th scope="row"><input type="checkbox" className={"appsCheckbox"}  id={"appSelectorCheckbox"+application.id} onClick={()=>this.checkCheckbox(application.id, application)}/></th>** 
            <td>{application.product}</td>
            </tr>
        )
        }
        return appSelectorArray;
     }

    checkboxStatus=()=> `this one is a validation of the checkbox clicks and it works as needed`
    {
        `I want to change the checkboxes status in here`
    }

checkCheckbox=(appId, application)=>
     {
        let contains=this.selectedApps.includes(appId)
        if (contains==false)
            {
                this.selectedApps.push(appId)
                this.selectedAppsObjArr.push(application)
            }
            else
            {
                let index=this.selectedApps.indexOf(appId);
                this.selectedApps.splice(index,1);
                let index2=this.selectedAppsObjArr.indexOf(appId)
                this.selectedAppsObjArr.splice(index2,1);
            }
     }

  sendForm = () => {
        this.toggleModal(); `Closing the Modal Window`
        this.addNewNetworks() ` Not important function`

        this.checkboxStatus(); `the above function`
      }

render (){

  return (
<Table striped bordered hover> `the table component`
                        <thead>
                        <tr>
                        <th>#</th>
                        <th>App</th>
                        </tr>
                        </thead>
                        <tbody>

Input checkbox in "chooseAppSelector"

                        {this.chooseAppSelector()}
                        </tbody>
                        </Table>

`divs....`
)

Thanks in advance!!

2
  • Pass a callback that clears the checkboxes to the modal. When the user clicks Done, you invoke the callback before/after doing the other things. Commented Jan 14, 2020 at 14:15
  • In your checkboxStatus function. Return an event and add it to your checkboxes like this: <input type="checkbox" checked={this.state.checked} onChange={this.onChangeAction.bind(this)} /> where this.state.checked = false. then call it at an appropriate time. Commented Jan 14, 2020 at 14:15

1 Answer 1

1

in your Done onClick handler add this 2 line :

handleDone=()=>{

   var clist=document.getElementsByClassName("appsCheckbox");
   for (var i = 0; i < clist.length; ++i) { clist[i].checked = false }

}
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.