Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

628
Views
ReactJs get id instead of value from Material UI Autocomplete

I'm using Material UI Auto complete to get list of countries, and I need to get the selected country id to send back to database.

<Autocomplete
   options={this.state.countries.map(option => option.name_en + ` (${option.name_native})`)}
   id="discountType"
   value={this.state.makeCountry}
   onChange={(e, value) => this.logCountry(e, value)}
   renderInput={(params) =>
   <TextField
      {...params}
      variant="outlined"
      label="Select make country"
   />}
/>

I need to send option.id to logCountry function alongside the value.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When creating your options, you can turn them into objects in a format such as:

const options = this.state.countries.map(option => ({ id: option.id, label: option.name_en + ` (${option.name_native})`}));

An then you can access the selected option id using onChange={(e, value) => this.logCountry(e, value.id)}.

I've forked the MUI Autocomplete's docs stackblitz example to implement such behavior, you can check it here.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!