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.36k stars 9.99k forks source link

How to validate the EditForm before click the submit button? #15292

Closed BerlyChristopher closed 4 years ago

BerlyChristopher commented 5 years ago

While placing the Input text component inside the EditForm, we can validate the form after clicking the submit button. How can we validate the component inside the edit form without clicking the submit button?

Can anyone suggest a possible solution?

PeterHimschoot commented 5 years ago

I'm working on a blog post explaining how to do this. I'll try to get it done tomorrow.

Peter Himschoot Author of Blazor Revealed

On Mon, Jul 15, 2019 at 7:20 PM Berly notifications@github.com wrote:

While placing the Input text component inside the EditForm, we can validate the form after clicking the submit button. How can we validate the component inside the edit form without clicking the submit button?

Can anyone suggest a possible solution?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/aspnet/Blazor/issues/1831?email_source=notifications&email_token=AAIJHPVKQYC6FGEWWUI6Z3LP7SWWTA5CNFSM4IDY7ZTKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4G7I2SVA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIJHPQLNVV67ID3K3LGCFLP7SWWTANCNFSM4IDY7ZTA .

danroth27 commented 5 years ago

@BerlyChristopher The EditorForm will setup an EditContext as a cascading value, which you should be able to call Validate() on. See https://docs.microsoft.com/aspnet/core/blazor/forms-validation for more details.

PeterHimschoot commented 5 years ago

As promised: https://blogs.u2u.be/peter/post/disabling-the-submit-button-in-blazor-with-validation

I think there is a small bug in EditForm because the EditContext property is null when you use Model.

On Mon, Jul 15, 2019 at 10:02 PM Daniel Roth notifications@github.com wrote:

Closed aspnet/Blazor#1831 https://github.com/aspnet/Blazor/issues/1831.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aspnet/Blazor/issues/1831?email_source=notifications&email_token=AAIJHPQ7TPOEEZ2WENALR4LP7TJW3A5CNFSM4IDY7ZTKYY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOSQH7HWQ#event-2484073434, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIJHPQNHUKZRODBF3KUCVTP7TJW3ANCNFSM4IDY7ZTA .

danroth27 commented 5 years ago

I think there is a small bug in EditForm because the EditContext property is null when you use Model.

Please file an issue on the https://github.com/aspnet/aspnetcore repo and we'll take a look.

PeterHimschoot commented 5 years ago

Hi Dan,

Done that already https://github.com/aspnet/AspNetCore/issues/12238

I'll even supply a PR :)

Peter

On Tue, Jul 16, 2019 at 6:46 PM Daniel Roth notifications@github.com wrote:

I think there is a small bug in EditForm because the EditContext property is null when you use Model.

Please file an issue on the https://github.com/aspnet/aspnetcore repo and we'll take a look.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/aspnet/Blazor/issues/1831?email_source=notifications&email_token=AAIJHPUJFXELTP3UBKEPJADP7X3O3A5CNFSM4IDY7ZTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2BOVFY#issuecomment-511896215, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIJHPUKFHLJ7F6CJR4ATUDP7X3O3ANCNFSM4IDY7ZTA .