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

undefined value on input and other elements #4467

Open
PatrickG opened this issue Feb 26, 2020 · 5 comments
Open

undefined value on input and other elements #4467

PatrickG opened this issue Feb 26, 2020 · 5 comments
Labels
bug compiler Changes relating to the compiler

Comments

@PatrickG
Copy link
Member

Describe the bug
The value prop behaves differently in various situations.

Suppose we have a variable let value = undefined.

If you use it on an input element with two-way binding <input bind:value />, the value is not set (this is the correct behavior, it got fixed in #3430).
If you use it on an input element like this: <input {value} />, the input elements value property is set to the string 'undefined' (not the attribute).
If you use it on any other element, like: <option {value} />, the value attribute is set to "undefined".

To Reproduce
https://svelte.dev/repl/9a8cf877df9a47948eb0cd3b04ea8372?version=3.19.1

Expected behavior
I think the value attribute (without two-way binding) should behave like the disabled attribute in the repl.

Severity
low

Additional context
You can get around it with <input value={value || ''} />

@Conduitry
Copy link
Member

Is this the same as #3569?

@tanhauhau tanhauhau added the dom label Mar 18, 2020
@PatrickG
Copy link
Member Author

Not really. Its more about the inconsistency when not using two-way binding vs using two-way binding.

@dgellow
Copy link

dgellow commented Oct 27, 2020

You can get around it with <input value={value || ''} />

That doesn't work as expected when using <input type="submit value={value || ''} />. That results in a submit button with no text instead of the expected "Submit".

Edit: it's a detail, just worth pointing out that this workaround has some unexpected effect.

@stale
Copy link

stale bot commented Jun 26, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale-bot label Jun 26, 2021
@stale stale bot removed the stale-bot label Jun 26, 2021
@pngwn pngwn added compiler Changes relating to the compiler bug stale-bot and removed feature: attributes temp-stale labels Jun 27, 2021
@stale stale bot removed the stale-bot label Jun 27, 2021
@PatrickG
Copy link
Member Author

This is fixed in Svelte 5

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

Successfully merging a pull request may close this issue.

6 participants