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

Select.Input defaults to the string value "undefined" #426

Closed
tylergannon opened this issue Feb 27, 2024 · 2 comments · May be fixed by #469
Closed

Select.Input defaults to the string value "undefined" #426

tylergannon opened this issue Feb 27, 2024 · 2 comments · May be fixed by #469
Labels
Svelte 5 Roadmap This issue is planned to be addressed or fixed when the library migrates to Svelte 5.

Comments

@tylergannon
Copy link

tylergannon commented Feb 27, 2024

Describe the bug

See the demo repo. The demo is in the root route. When user makes no selection in a Select control and then posts the form, the Select.Input hidden input will post the string value "undefined".

I'd like to suggest that the appropriate thing would be to post empty string or else omit the hidden input from the form post.

If this is by design, it might be good to denote it as such in the docs so that authors using this control know what to test for in their form action backend code.

Reproduction

  1. Clone the demo repo https://github.com/tylergannon/shadcn-select-empty-value and start up the dev server.
  2. Navigate to the root route.
  3. Click the submit button without making a selection in the select control.

Expect: An empty string or no value to be submitted.
Actual: The string value "undefined" will be submitted.

Logs

No response

System Info

System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M1
    Memory: 33.09 MB / 16.00 GB
    Shell: 3.7.0 - /opt/homebrew/bin/fish
  Binaries:
    Node: 21.6.2 - /opt/homebrew/bin/node
    npm: 10.2.4 - /opt/homebrew/bin/npm
    pnpm: 8.15.4 - /opt/homebrew/bin/pnpm
    bun: 1.0.29 - /opt/homebrew/bin/bun
  Browsers:
    Safari: 17.2.1
  npmPackages:
    @sveltejs/kit: ^2.0.0 => 2.5.2
    bits-ui: ^0.18.3 => 0.18.3
    svelte: ^4.2.7 => 4.2.12

Severity

annoyance

@huntabyte huntabyte transferred this issue from huntabyte/shadcn-svelte Mar 28, 2024
@emilkjuka
Copy link

emilkjuka commented Apr 7, 2024

For now I have found a workaround this. I basically create a emptySelection object const emptySelection={value: '', label:''}
and pass it as selected inside the Root of the select element.
With this my zod validation works but you need to also specify the min function to check for a value of >1. Then it will show your validation message as well.

@huntabyte huntabyte mentioned this issue Jun 9, 2024
3 tasks
@huntabyte huntabyte mentioned this issue Jul 31, 2024
70 tasks
@huntabyte huntabyte added the Svelte 5 Roadmap This issue is planned to be addressed or fixed when the library migrates to Svelte 5. label Oct 3, 2024
@huntabyte
Copy link
Owner

Closing as fixed in bits-ui@next

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Svelte 5 Roadmap This issue is planned to be addressed or fixed when the library migrates to Svelte 5.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants