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

148
Views
How to set value and option in material UI AutoComplete and onChange assign the value to a object?

I have a brand object with the field cat_id, on page load categories load into autocomplete select. Now I want to set category id as a value with a category option in autocomplete and also set cat_id from the autocomplete option value onChange.

const handleChange = (e) => {
  const { name, value } = e.target;
  setBrand({
    ...brand,
    [name]: value,
  });
};

<Autocomplete
  getOptionSelected={(option, value) => option.category_name === value.id}
  getOptionLabel={(option) => option.category_name}
  name="cat_id"
  onInputChange={handleChange}
  options={categories}
  loading={loading}
  renderInput={(params) => (
    <TextField
      {...params}
      label="Category"
      fullWidth
      variant="outlined"
      required
      InputProps={{
        ...params.InputProps,
        endAdornment: (
          <Fragment>
            {" "}
            {loading ? <CircularProgress color="inherit" /> : null}{" "}
            {params.InputProps.endAdornment}
          </Fragment>
        ),
      }}
    />
  )}
/>;

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

0

After waiting a while for the help. I manage to solve this but I'm not sure is this a recommended way. I directly set the field value onChange and didn't use handleChange function.

<Autocomplete
  getOptionSelected={(option, value) => option.category_name === value.id}
  getOptionLabel={(option) => option.category_name}
  name="cat_id"
  options={categories}
  loading={loading}
  onChange={(e,option) => setBrand({...brand,cat_id: option.id,})}
  renderInput={(params) => (
    <TextField
      {...params}
      label="Category"
      fullWidth
      variant="outlined"
      required
      InputProps={{
        ...params.InputProps,
        endAdornment: (
          <Fragment>
            {" "}
            {loading ? <CircularProgress color="inherit" /> : null}{" "}
            {params.InputProps.endAdornment}
          </Fragment>
        ),
      }}
    />
  )}
/>;
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!