mercredi 9 janvier 2019

React Native - CheckBox unable to uncheck the "cheked" box

I've been using React native for a month now but it's my first time to use a CheckBox in my application. So, lately I've been struggling to check a specific checkbox inside a Flatlist but now I can.

But upon testing my checkboxs I did notice that once I check a specific a CheckBox(or more than 1 checkbox) it doesn't UNCHECK.

So, my goal is to make a CheckBox that can check(ofcourse) and also uncheck, if ever a user mischeck or mistap a CheckBox.

Here's my code

export default class tables extends Component {
    constructor(props){
        super(props)
        this.state = {
            ...
            check: false
        }
    }
    checkBox_Test = (item, index) => {
        let { check } = this.state;
        check[index] = !check[index];
        this.setState({ check: check })

        alert("now the value is " + !this.state.check);
        alert("now the value is " + item.tbl_id);
        console.log(item.tbl_id)
    }
    render() {
        return(
             <View>
                  ....
                  <Flatlist
                        ....
                        <CheckBox
                           value = { this.state.check }
                           onChange = {() => this.checkBox_Test(item) }
                        />
                        ....
                  />
             <View/>
        )
    }
}

Screen_Shot_Sample




Aucun commentaire:

Enregistrer un commentaire