Skip to content
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] Uncaught TypeError: Cannot read property 'length' of null #20152

Closed
aaronhayes opened this issue Mar 17, 2020 · 10 comments
Closed
Labels
component: autocomplete This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement

Comments

@aaronhayes
Copy link

aaronhayes commented Mar 17, 2020

TypeError · Uncaught TypeError: Cannot read property 'length' of null

https://github.com/mui-org/material-ui/blob/701e3ad76b788a50ea83aeb8516ed303c2435bd0/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js#L821

If value is null and multiple is true, we run into this error. Should add a check for value being null.

Version: "@material-ui/lab": "^4.0.0-alpha.45"

@eps1lon
Copy link
Member

eps1lon commented Mar 17, 2020

@aaronhayes Please provide a full reproduction test case. This would help a lot 👷 .
A live example would be perfect. This codesandbox.io template may be a good starting point. Thank you!

@eps1lon eps1lon added status: waiting for author Issue with insufficient information component: autocomplete This is the name of the generic UI component, not the React module! labels Mar 17, 2020
@aaronhayes
Copy link
Author

Yep will see what I can put together @eps1lon

@ohlr
Copy link
Contributor

ohlr commented Mar 17, 2020

@eps1lon This should be a sufficient test case

        <Autocomplete
            options={options}
            getOptionLabel={option => option.label}
            value={null}
            onChange={(event: any, newValue: any) => {
                handleOptionsIdChange(newValue);
            }}
            multiple={true}
            renderInput={params => (
                <TextField {...params} label="test" variant="standard" fullWidth />
            )}
        />

@dfyz011
Copy link

dfyz011 commented Apr 21, 2021

I still have problem here in combination with react-form-hooks:
https://github.com/mui-org/material-ui/blob/42954448866f204b0cf7e35127d5d0af9c24d6fb/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js#L896

Version: "@material-ui/lab": "^4.0.0-alpha.56"

@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement and removed status: waiting for author Issue with insufficient information labels Apr 21, 2021
@oliviertassinari
Copy link
Member

@ohlr This is not valid, #20152 (comment) throw types and prop-types warnings. null is not a valid value

@parksj10
Copy link

Why is null not a valid value? the standard autcomplete (I.e. no multiple) accepts null values... Shouldn't we be able to set null (I.e. no values) for a multiple autocomplete?

@oliviertassinari
Copy link
Member

@parksj10 you can provide an empty array instead.

@frontendDevResearcher
Copy link

if you provide an empty array, the autocomplete multiple selection will stop working.

@frontendDevResearcher
Copy link

@oliviertassinari

@frontendDevResearcher
Copy link

I was trying to use this hack as I was also getting [Autocomplete] TypeError: (intermediate value)(intermediate value)(intermediate value).filter is not a function error my this line solved the issue value={undefined} but then I started getting
this error for that, I tried this value={item.type === "multiSelect" ? [] : undefined}
now , no errors but the values are not coming on the autoComplete selection

<Autocomplete
                        multiple={item.type === "multiSelect"}
                        css={`
                          margin-top: 4px;
                        `}
                        value={item.type === "multiSelect" ? [] : undefined}
                        fullWidth
                        options={item.values || []}
                        getOptionLabel={(option) => option.label || ""}
                        renderInput={(params) => (
                          <TextField {...params} variant="standard" />
                        )}
                      />
                      ```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

7 participants