<option value=""> incorrectly omits value attribute
See original GitHub issueBug
<option value="">[Select]</option> becomes <option>[Select]</option> on the client thus eliminating the ability to select "nothing" as a value in a drop down.To Reproduce
<div><input id="tbx" value="@MyValue" /></div>
<div>
<select id="ddlAdm1" @onchange="@OnMyValChange" value="@MyValue">
<option value="">[Select]</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
</div>
@code {
[Parameter] public string MyValue { get; set; }
protected void OnMyValChange(ChangeEventArgs e)
{
MyValue = e.Value.ToString();
}
}
Produces
<div><input id="tbx"></div><!--!-->
<div>
<!--!-->
<select id="ddlTest">
<!--!-->
<option>[Select]</option><!--!-->
<option value="1">One</option><!--!-->
<option value="2">Two</option><!--!-->
</select><!--!-->
</div>
This causes selecting the first line to put “[Select]” in the “tbx” input box.
Version Info
.NET Core SDK (reflecting any global.json): Version: 3.1.100 Commit: cd82f021f4
Runtime Environment: OS Name: Windows OS Version: 6.3.9600 OS Platform: Windows RID: win81-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.100\
Host (useful for support): Version: 3.1.0 Commit: 65f04fb6db
Visual Studio 2019
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks very much @jonbrauer for reporting this and for providing such a clear repro.
This is a bug and will be fixed in https://github.com/aspnet/AspNetCore/pull/17838. In the meantime, the workaround I’d recommend is to have a different value (other than an empty string) to represent “no selection”, and set that value as the initial value for your bound model property.
GREAT! Thanks so much!
From: Steve Sanderson notifications@github.com Reply-To: aspnet/AspNetCore reply@reply.github.com Date: Thursday, December 12, 2019 at 1:54 PM To: aspnet/AspNetCore AspNetCore@noreply.github.com Cc: AppSupport AppSupport@gc.adventist.org, Mention mention@noreply.github.com Subject: Re: [aspnet/AspNetCore] <option value=""> incorrectly omits value attribute (#17735)
Thanks very much @jonbrauerhttps://github.com/jonbrauer for reporting this and for providing such a clear repro.
This is a bug and will be fixed in #17838https://github.com/aspnet/AspNetCore/pull/17838. In the meantime, the workaround I’d recommend is to have a different value (other than an empty string) to represent “no selection”, and set that value as the initial value for your bound model property.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/aspnet/AspNetCore/issues/17735?email_source=notifications&email_token=AOAEGHARVGFUNW2LENZPSFLQYKCD3A5CNFSM4JY7EKHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGXUXSQ#issuecomment-565136330, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOAEGHG4ERY4SW2AJPSKMGDQYKCD3ANCNFSM4JY7EKHA.