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.56k stars 10.05k forks source link

Include valid/invalid state in ValidationStateChangedEventArgs #13413

Open mrpmorris opened 5 years ago

mrpmorris commented 5 years ago

Is your feature request related to a problem? Please describe.

I'm trying to detect when a Blazor EditForm's valid state changes so I can enable/disable a Submit button.

Describe the solution you'd like

Add an IsValid Boolean property to ValidationStateChangedEventArgs, and also add a ValidationStateChanged event to EditForm.

Additional context

Add any other context or screenshots about the feature request here.

pranavkm commented 5 years ago

@mrpmorris thanks your issue report. The sender parameter in the event handlers would be an instance of EditContext which you could use to access the validation state. The event args could do with some improvement. For now, we'll park this in the backlog and wait for more community asks for this feature..

mrpmorris commented 5 years ago

That's a bit elusive, and involves the evil typecast approach. It also means a cost of more CPU cycles.

The args update would be much better.

StevenGranados commented 4 years ago

I'm also missing this feature. Would be very useful.

DominikPf commented 4 years ago

I could cast sender as EditContext, but currently there is no IsValid Property in EditContext. Only Validate() would return the ValidationState. But this would cost additional Resources to Re-Validate. And would end up in an endless loop. (ValidationChangedEvent->Validate->ValitationChangedEvent->...)

BrownBot commented 3 years ago

IsValid = EditContext.GetValidationMessages().Count() == 0;

Seems to work, but it's not elegant.

Bertramp commented 2 years ago

@BrownBot That only works if you have added any validation messages. But i will use it for now..

Working with forms is really handicapped by having no way to access the state of a context without re-validating which often can be super expensive. This needs to be a property on the EditContext or ValidationStateChangedEventArgs

mcanic commented 2 years ago

end of sept 2022, and this is still not fixed. I have a submit button outside the form that should be disabled if the form is invalid. The button is also in the parent component, so I have to raise an event. It would be better to have the form state passed as bool in the ValidationStateChangedEventArgs. Now we have to resort on @BrownBot's suggestion using IsValid = EditContext.GetValidationMessages().Count() == 0;. Please add this small but valueable improvement!

ghost commented 2 years ago

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

mcanic commented 2 years ago

It would also be nice to be able to programmatically submit an EditForm. With this it would be easier to submit a form from another component. OnValidSubmit is the only event to catch a form submit. That's fine, but if we want to trigger the submit from an other component than a submit button in the editform or a button elsewhere with the form attribute referring to the editform id, then it's not possible without javascript.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mkArtakMSFT commented 11 months ago

@SteveSandersonMS can you please fill in the summary comment from the https://github.com/dotnet/aspnetcore/blob/main/docs/HelpWantedProcess.md and turn this into a help wanted issue? Thanks!

ghost commented 11 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.