why my app can’t handle the radio button selected value of the form?

I am new to ReactJS, sorry if this sounds off. I am trying to create a user with a form that contains a multi radio buttons field. when a fill up the form and then submit the document is stored in database but the type field is empty. And thats where I am stuck.

class SignupForm extends Component {
    constructor(props) {
        super(props);
        this.state = {
            name: '',
            email: '',
            prenom: '',
            password: '',
            type:String
        }
        this.handleInputChange = this.handleInputChange.bind(this);
        this.handleSubmit = this.handleSubmit.bind(this);

      
    }

    handleInputChange(event) {
        const target = event.target;
        const inputName = target.name;        
        const inputValue = target.value;

        this.setState({
            [inputName] : inputValue
        });        
    }

    handleSubmit(event) {
        event.preventDefault();   

        const signUpRequest = Object.assign({}, this.state);

        signup(signUpRequest)
        .then(response => {
            Alert.success("Votre inscrption est réussi. Veuillez s'authentifier pour continuer!");
            this.props.history.push("/login");
        }).catch(error => {
            Alert.error((error && error.message) || 'Oops! Il y a un erreur de saisi . Veuiller saisir une autre fois!');            
        });
    }

//

<label><input type="radio" value="medecin" name="type" value={this.state.type} onChange={this.handleInputChange} required/>Médecin</label><br/>
                <label id="aaa"><input type="radio" value="Patient"  name="type" value={this.state.type} onChange={this.handleInputChange} required/>Patient</label><br/>
                <label id="aa"><input type="radio" value="Laboratoire" name="type" value={this.state.type} onChange={this.handleInputChange} required/>Laboratoire</label><br/>
                <label id='a'><input type="radio" value="pharmacie"  name="type" value={this.state.type} onChange={this.handleInputChange} required/>Pharmacie</label><br/>

An example of a document stored in database:

{
"_id":{"$oid":"607012c3c500325c3ec18bb7"},
"name":"racha",
"prenom":"qdqsd",
"email":"qds@sfd.c",
"emailVerified":false,
"password":"$2a$10$5aK8yJIQ40lbPP.vfGWoNeVnXiyHOIIVpa2yyXRKL8eyMmgCRWO8C",
"provider":"local",
"type":"",
"_class":"com.example.springsocial.model.User"
}


Read more here: https://stackoverflow.com/questions/67018051/why-my-app-cant-handle-the-radio-button-selected-value-of-the-form

Content Attribution

This content was originally published by dali hmida at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: