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

1.1K
Views
MUI: el valor proporcionado para Autocompletar no es válido. Ninguna de las opciones coincide con `0`

Estoy usando el componente de autocompletar MUI con forma de gancho de reacción . Seguí esta respuesta .

ControlledAutoComplete.jsx

 import { Autocomplete, TextField } from "@mui/material"; import React from "react"; import { Controller } from "react-hook-form"; const ControlledAutoComplete = ({ options = [], label, renderInput, getOptionLabel, control, defaultValue, name, errors, }) => { return ( <Controller defaultValue={defaultValue} name={name} control={control} render={({ field }) => ( <Autocomplete options={options} getOptionLabel={getOptionLabel} defaultValue={defaultValue} renderInput={(params) => ( <TextField {...params} label={label} error={errors[name]} helperText={errors[name] && errors[name].message} onChange={(e, data) => field.onChange(data)} /> )} {...field} isOptionEqualToValue={(option, value) => value === undefined || value === "" || option.id === value.id } /> )} /> ); }; export default ControlledAutoComplete;

AddFees.jsx

 <ControlledAutoComplete control={control} name="enrollmentId" options={[{ id: 1, firstName: "John"}, { id: 2, firstName: "Jen" }]} getOptionLabel={(option) => `${option.firstName}`} label="Select Students" errors={errors} defaultValue={""} />

Me estoy poniendo por debajo de la advertencia,

MUI: el valor proporcionado para Autocompletar no es válido. Ninguna de las opciones coincide con 0 . Puede usar la propiedad isOptionEqualToValue para personalizar la prueba de igualdad.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

lo estaba haciendo mal Estaba escuchando onChange en el campo de texto mientras debería estar en AutoComplete

 const ControlledAutoComplete = ({ options = [], label, renderInput, getOptionLabel, control, defaultValue, name, errors, }) => { return ( <Controller name={name} control={control} defaultValue={defaultValue} render={({ field }) => ( <Autocomplete options={options} getOptionLabel={getOptionLabel} renderInput={(params) => ( <TextField {...params} label={label} error={errors[name]} helperText={errors[name] && errors[name].message} /> )} {...field} isOptionEqualToValue={(option, value) => value === undefined || value === "" || option.id === value.id } onChange={(_, data) => field.onChange(data)} /> )} /> ); };

Uso,

 <ControlledAutoComplete control={control} name="enrollmentId" options={students} getOptionLabel={(option) => `${option.firstName}`} label="Select Students" errors={errors} defaultValue="" />

Ejemplo de caja de arena

about 4 years ago · Santiago Trujillo 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!