mercredi 2 octobre 2019

How to add multiple checkboxes to a state

How to save multiple checkboxes to a single state and add each checkbox to its previous state

this is my states

        Operators : '',
        TypeStatus : '',
        RegistrationStatus : '',

this is my function

changeHandle = (event) => {
    this.setState({
        [event.target.name]:  event.target.value
    });
};

this is my inputs

                                            <div className="col" data-toggle="buttons">
                                                <label className={`RegisterButtons ${this.state.Operators === "MCI" ? 'RegisterButtonsActivated' : ''}`}>
                                                    <input
                                                        type="checkbox"
                                                        name="Operators"
                                                        id="MCI"
                                                        value="MCI"
                                                        onChange={this.changeHandle}
                                                        onClick={this.handleClickOperators.bind(this)}
                                                    />
                                                    همراه اول
                                                </label>
                                            </div>

                                            <div className="col" data-toggle="buttons">
                                                <label className={`RegisterButtons ${this.state.Operators === "irancell" ? 'RegisterButtonsActivated' : ''}`}>
                                                    <input
                                                        type="checkbox"
                                                        name="Operators"
                                                        id="irancell"
                                                        value="irancell"
                                                        onChange={this.changeHandle}
                                                        onClick={this.handleClickOperators.bind(this)}
                                                    />
                                                    ایرانسل
                                                </label>
                                            </div>

                                            <div className="col" data-toggle="buttons">
                                                <label className={`RegisterButtons ${this.state.Operators === "rightel" ? 'RegisterButtonsActivated' : ''}`}>
                                                    <input
                                                        type="checkbox"
                                                        name="Operators"
                                                        id="rightel"
                                                        value="rightel"
                                                        onChange={this.changeHandle}
                                                        onClick={this.handleClickOperators.bind(this)}
                                                    />
                                                    رایتل
                                                </label>
                                            </div>                       

How to save multiple checkbox to a single state and add each checkbox to its previous state




Aucun commentaire:

Enregistrer un commentaire