question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<option value=""> incorrectly omits value attribute

See original GitHub issue

Bug

<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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveSandersonMScommented, Dec 12, 2019

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.

0reactions
appsupport-gccommented, Dec 12, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found