-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Autocomplete] TypeError: (intermediate value)(intermediate value)(intermediate value).filter is not a function #24785
Comments
Please provide a minimal reproduction test case. This would help a lot 👷 . |
@oliviertassinari when you search in autocomplete by typing it it will give error inother cases works fine @oliviertassinari Thanks for help |
@bipindubey-technoark Thanks for providing a reproduction. I have updated to v5: https://codesandbox.io/s/material-ui-issue-forked-s0m4o?file=/src/Demo.js We now have a proper error message: |
I didnt understood the exact issue?? |
this is giving this error because you have provided ff to the value but i provided an array which should work |
@bipindubey-technoark in your codesandbox, if you upgrade it to v5, too, you will see that the value becomes a string. |
But in my case value in not string. it is an array. I am definitely sure that i have not provided a string .. |
@oliviertassinari What you have done in v5 and why you put static value ff i dont know.. |
I fixed the issue in renderInput function of autocomplete just change <Field
{...params}
label="All Users"
fullWidth
name="userIds"
component={TextField}
/> to
Note: MuiTextfield is material ui textfield and Textfield is formik Textfield import {
TextField as MuiTextField,
} from '@material-ui/core';
import { TextField } from 'formik-material-ui'; Thanks |
In my case I was passing string as default value |
@ImranHaider313 Interesting feedback. We could apply the prop-types logic of the diff --git a/packages/material-ui/src/Autocomplete/Autocomplete.js b/packages/material-ui/src/Autocomplete/Autocomplete.js
index 0b3f81981c..c7a25a9a4d 100644
--- a/packages/material-ui/src/Autocomplete/Autocomplete.js
+++ b/packages/material-ui/src/Autocomplete/Autocomplete.js
@@ -770,7 +770,17 @@ Autocomplete.propTypes /* remove-proptypes */ = {
* The default value. Use when the component is not controlled.
* @default props.multiple ? [] : null
*/
- defaultValue: PropTypes.any,
+ defaultValue: chainPropTypes(PropTypes.any, (props) => {
+ if (props.multiple && props.defaultValue !== undefined && !Array.isArray(props.defaultValue)) {
+ return new Error(
+ [
+ 'Material-UI: The Autocomplete expects the `defaultValue` prop to be an array or undefined.',
+ `However, ${props.defaultValue} was provided.`,
+ ].join('\n'),
+ );
+ }
+ return null;
+ }),
/**
* If `true`, the input can't be cleared.
* @default false |
@oliviertassinari can I work on this (over the weekend) ? |
I had the same issue and was able to fix by making use |
My error was apparently happening because of missing value prop. I added it as follows and it worked: value={undefined} Note: I am using mui-rff ("mui-rff": "^5.0.0")
|
@jbham Setting |
I'm using <Controller
control={control}
name={name}
render={({ field }) => (
<Autocomplete
{...field}
multiple
defaultValue={[]}
value={field.value ? field.value : []}
filterSelectedOptions
getOptionLabel={option => option.label}
disablePortal
PaperComponent={AutocompletePaper}
options={options as Array<Record<string, string>>}
onChange={(e, val) => {
field.onChange(val);
onChange();
}}
fullWidth
renderInput={params => (
<TextField
type={type}
label={label}
variant="outlined"
{...params}
value={params.inputProps.value ?? ''}
/>
)}
/>
)}
/> Clear function const handleClear = () => {
removeDynamicParam();
Object.keys(form.getValues()).forEach(formField => {
form.setValue(formField, '');
});
refetch();
}; The main attention is on these fields:
This way I'm not getting that error and Autocomplete getting cleared. |
I am integrating autocomplete component in my website
it is crashing when we type anything in the autocomplete field
it is giving following error
Uncaught TypeError: (intermediate value)(intermediate value)(intermediate value).filter is not a function in autocomplete
My code:
my values:
values.userIds = [1,2];
users = [
{id:1,firstName:'A', lastName:'B'},
{id:2,firstName:'P', lastName:'Q'},
{id:3,firstName:'X', lastName:'Y'},];
it is working fine on every other case like clicking on dropdown icon and then choosing the option or removing it by clicking on close icon
but crashing when we start to type anything in the field
Thanks
The text was updated successfully, but these errors were encountered: