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

Empty values in createOption with trimmed value #409

Open
mathieutu opened this issue May 11, 2024 · 1 comment
Open

Empty values in createOption with trimmed value #409

mathieutu opened this issue May 11, 2024 · 1 comment

Comments

@mathieutu
Copy link

mathieutu commented May 11, 2024

Version

  • Vue version: 3

Description

Hi, thanks for your work.
I'm trying to trim values that are created. However, if you only enter a space , we can avoid to create the option but not avoid to show and empty one in the list.

Ex: (spaces are in the search bar)

Screenshot 2024-05-11 at 14 30 57 Screenshot 2024-05-11 at 14 31 12

It would be great to be able to sanitize the search query to trim the value here directly.

Another solution would be to execute onCreate directly in createdOption, so we would filter it directly, and even allow to change the property (including label, when showed).

const createdOption = computed(() => {
if (createOption.value === false || !search.value) {
return []
}
if (getOptionByTrackBy(search.value) !== -1) {
return []
}
return [{
[valueProp.value]: search.value,
[trackBy.value[0]]: search.value,
[label.value]: search.value,
__CREATE__: true,
}]
})

Happy to create the PR if you want to.

Demo

https://jsfiddle.net/hvko13n0/2/

@mathieutu
Copy link
Author

For now I patched the package with:

   const handleSearchInput = (e) => {
-    search.value = e.target.value;
+    search.value = e.target.value.trim();
   };

And it seems to work great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant