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] Prevent form submit with freeSolo and multiple #18958

Closed
michael-land opened this issue Dec 23, 2019 · 7 comments · Fixed by #19072
Closed

[Autocomplete] Prevent form submit with freeSolo and multiple #18958

michael-land opened this issue Dec 23, 2019 · 7 comments · Fixed by #19072
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@michael-land
Copy link
Contributor

image

https://codesandbox.io/s/vibrant-water-pepu1

@oliviertassinari oliviertassinari added component: autocomplete This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work good first issue Great for first contributions. Enable to learn the contribution process. labels Dec 25, 2019
@morijenab
Copy link
Contributor

morijenab commented Dec 27, 2019

You can enable "required" tag in your textfield.
Do you expect the same behavior without using "reqiured" tag?

@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 27, 2019

I think that this is a leftover during the initial implementation. I would propose the following diff:

diff --git a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
index 7a799b1b81..8baf322864 100644
--- a/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
+++ b/packages/material-ui-lab/src/useAutocomplete/useAutocomplete.js
@@ -586,6 +586,10 @@ export default function useAutocomplete(props) {
             );
           }
         } else if (freeSolo && inputValueFilter !== '') {
+          if (multiple) {
+            // Allow people to add new values before they submit the form.
+            event.preventDefault();
+          }
           selectNewValue(event, inputValue);
         }
         break;

Does somebody want to work on a pull request? :)

@oliviertassinari oliviertassinari changed the title [Autocomplete] Should input prevent form submit by default when use freeSolo and multiple mode? [Autocomplete] Prevent form submit with freeSolo and multiple Dec 27, 2019
@morijenab

This comment has been minimized.

@oliviertassinari

This comment has been minimized.

@morijenab

This comment has been minimized.

@haseebdaone
Copy link
Contributor

Hi I would like to give this a go and also this will be my first contribution ever

@oliviertassinari
Copy link
Member

@haseebdaone You are good to go :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: autocomplete This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants