Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiple inputs handling in react js

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 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

>Solution :

Try to change your handleInputs function like this:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading