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.38k stars 10k forks source link

Reject Data on @OnChange event on a textbox. #51733

Closed b-giavotto closed 11 months ago

b-giavotto commented 12 months ago

Is there an existing issue for this?

Describe the bug

BlazorServer: apparently there is no way to reject changes to an input box in a onchange event.

Expected Behavior

Steps to reproduce the problem: place an input box, and bind it's value property to a page property called string inputvalue. also bind an onchange event to an eventhandler called checkvalue. Add some code to reject an invalid value and some other to accept the value like this:

public void checkvalue(ChangeEventArgs args)
{
// if the value is OK we update the inputvalue property that is bould to a value attribute of input otherwise not.

if (isvalid)
{
inputvalue = .....
}

}

Steps To Reproduce

enter an invalid value, by violating the rule applyed on server. in the input. the value should be reverted back as you focus to another control. however this does not happen.

That is because, we are keeping the old value server side so the diffing algo does not apply any change to the input box. Actually the only workaround is to invoke a javascript function that force the textbox value to the old value.

Is there a way a more elegant solution?

Thx Best regards.

Exceptions (if any)

none

.NET Version

does not apply

Anything else?

.

ghost commented 11 months ago

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

ghost commented 11 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

See our Issue Management Policies for more information.