Please see the following code at first.
I want the particular checkbox (with id cfc1) to not be shown ticked whenever clicking on it.
I have used the onCheck function there. I'm not finding any way to the particular element be shown unchecked whenever clicked on it. I'm trying using the code -
if(e.currentTarget.id === 'cfc1') {
document.getElementById(e.currentTarget.id).checked = false;
}
but it's not working.
How to do it using the onCheck function?
import React, {Component} from 'react';
import Checkbox from 'material-ui/Checkbox';
class Checkboxes extends Component {
constructor() {
super();
this.state = {
checkids:['cfc0', 'cfc1', 'cfc2', 'cfc3']
};
this.handleCheck = this.handleCheck.bind(this);
this.getElements = this.getElements.bind(this);
}
getElements() {
let arr = [];
this.state.checkids.forEach(function(element) {
arr.push(
<Checkbox
id={element}
onCheck={this.handleCheck}
/>
);
}, this)
return arr;
}
handleCheck(e) {
console.log(e.currentTarget.id);
console.log(e.currentTarget.checked);
}
render() {
return(
<div>
{this.getElements()}
</div>
);
}
}
export default Checkboxes