Skip to content

For invalid inputs in input type number, the bound value (using bind:value={val}) is null and not undefined. #15811

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

Open
theAnuragMishra opened this issue Apr 21, 2025 · 2 comments · May be fixed by #15834

Comments

@theAnuragMishra
Copy link

Describe the bug

https://svelte.dev/docs/svelte/bind#input-bind:value
the docs here say it is undefined in the case of an empty or a invalid input. but is null in the case of an invalid input.

Reproduction

https://svelte.dev/playground/064fcdbe349a4ee2887a12ee696b5730?version=5.28.1

Logs

System Info

i m using svelte playground, svelte 5.28.1.

Severity

annoyance

@Ocean-OS
Copy link
Contributor

I'm not sure if this is a documentation issue or an actual bug, since the code explicitly defaults to null for invalid inputs.

@theAnuragMishra
Copy link
Author

theAnuragMishra commented Apr 22, 2025

I'm not sure if this is a documentation issue or an actual bug, since the code explicitly defaults to null for invalid inputs.

function to_number(value) {
	return value === '' ? null : +value;
}

my understanding of the code: it should return null for empty input and NaN for invalid inputs.
the docs mention: it should return undefined for empty and invalid inputs.
the actual behaviour: returns undefined for empty inputs but null for invalid inputs.

it's so confusing :)

@7nik 7nik linked a pull request Apr 25, 2025 that will close this issue
6 tasks
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

Successfully merging a pull request may close this issue.

2 participants