Home > Mobile >  Multiple inputs handling in react js
Multiple inputs handling in react js

Time:11-26

I want to update a form, so that I have fetch data from backend and display in form.I have declare form data like

constructor()
    {
        super()
        this.state={
          organization:[],
          options:["IT service", "Design"],
          loading:true,
          modalIsOpen: false,
          formData:{
            org_name:'',
            org_code:'',
            org_type:'',
            org_category:'',
            org_location:'',
            org_registration:'',
        }
         
        }

Then my handleinput function

handleInputs = (e) => {
      this.setState ({
        formData:{
        [e.target.name]:e.target.value
        }
       });
    }

and my update url

 updateOrganization = async(e) =>
      {
       const org_id= 
        e.preventDefault();
       const res=await axios.put('http://localhost:8000/api/update_organization',this.state.formData);
       
      }

But have six input fields, but when I trying to submit form I got only one input. I am new in react js.Please Help me

CodePudding user response:

Try to change your handleInputs function like this:

handleInputs = (e) => {
  this.setState({
    formData: {
      ...this.state.formData,
      [e.target.name]: e.target.value,
    },
  });
};
  • Related