dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

Blazor EditForm reverting changed inputs to previous #28788

Closed bdlawrence13 closed 3 years ago

bdlawrence13 commented 3 years ago

Have tried to work through this, but believe something isn't working as it should.

I have a Blazor EditForm (code below) where I read the model object in to pre-populate. The form's function is to edit values read from the database. However, when I change the value in a text input or any other input, then go to the next field, the previous field reverts back to the previous value. I cannot get the value to change.

Here's the relevant code:

@inject fullRentalOrderObject ROObject

// This prepopulates the object.
@{
    ROObject.getRentalOrder(sharedVariables.editRONum);
}

<EditForm Model="@ROObject" OnValidSubmit="@HandleValidSubmit">

<p>
        <label>
            Serial #:
            <InputText @bind-Value="@ROObject.rentalOrder.sn" />
        </label>
    </p>
    <p>
        <label>
            POHD (No = Has POHD, Yes = Needs POHD):
            <InputCheckbox @bind-Value="@ROObject.rentalOrder.pohd" />
        </label>
    </p>
    <p>
        <label>
            Service Center:
        </label>
        <InputText @bind-Value="@ROObject.rentalOrder.svcCentre" size="50" @onchange="getROPs" />
    </p>    <button class="btn btn-primary" type="submit">Submit</button>

    &nbsp &nbsp &nbsp &nbsp
    <button class="btn btn-primary" @onclick="CancelPatientInput">Cancel</button>  

</EditForm>

In the above, let's say Serial Number = "12345", POHD is unchecked and Service Center = "Phoenix". If I change "12345" in Serial number to "434343" then go to Service Center, the value changes back in Serial Number to "12345" If I check POHD, then to go Service Center, POHD is unchecked.

I can't find anything in the documentation. This isn't the behavior if I use input type="text"... If I use the same form, only don't initialize the object - adding new values to a blank object, this works fine. What Blazor seems to not allow me to do is edit values.

Also, using the onchange="getROPs" in service center - this is never called within the InputText call.

Appears to be a problem with how either the input controls, the EditForm or the binding is working.

bdlawrence13 commented 3 years ago

Sorry, not all the code came through. Had to remove the HTML tags, as this form wanted to treat them as HTML, not text.

EditForm Model="@ROObject" OnValidSubmit="@HandleValidSubmit" Serial #: InputText @bind-Value="@ROObject.rentalOrder.sn"

        POHD (No = Has POHD, Yes = Needs POHD):
        InputCheckbox @bind-Value="@ROObject.rentalOrder.pohd"

        Service Center:
    InputText @bind-Value="@ROObject.rentalOrder.svcCentre" size="50" @onchange="getROPs"

button class="btn btn-primary" type="submit">Submit

end EditForm

mkArtakMSFT commented 3 years ago

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project (ideally a GitHub repo) that illustrates the problem.

bdlawrence13 commented 3 years ago

Found a work around. No longer an issue.