-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow hiding ValidationSummary content when there are no errors #2372
Comments
Can you explain this a little more? What do you mean by "custom code"? Are you saying the |
Exactly, and the button too. I currently have :
to achieve the desired output. I'm on beta3 btw. |
@Bartmax I definitely see the value in this. I have had similar problems before when trying to add additional content or styling to the validation summary div. The problem with the conditional rendering you are using now is that it doesn't work with client side validation. In some cases, model level errors will not be displayed on the client side because the div is not there. I think this might be something that is better handled on the client side. If there is a class or attribute added to the validation summary then we can easily handle the show/hide via CSS. This would likely require a change to both the unobtrusive validation JS and the server side GenerateValidationSummary code. |
This is supported today: The |
@dougbu note that validation-summary class is custom app class, not framework one css:
cshtml:
I'm not sure if there's anything to do here, I leave it just in case. Feel free to close it. |
There is something we could do though it may cause more trouble than it's worth. My "supported today" point was specifically about existing CSS classes. We could add an optional attribute to the |
The way this currently works (beta7) seems unintuitive to me: using While I understand that |
Maybe we need a validation-summary-initial class with a default display:none, for the 'missing' state. There are 3 states, initial, valid and error. We currently have classes for valid and error. Do you think it add value to have a validation-summary-initial class ? |
Probably easier to just always apply a class of .validation-summary { display:none; }
.validation-summary.validation-summary-valid, .validation-summary.validation-summary-error { display: block; } |
@Eilon please see my comment above. We should make this simple change for the next release if possible, please re-triage. |
that will work 👍 just wanted to note, with validation-summary-valid you don't want to display the div.
|
@Bartmax yeah that 😄 |
@DamianEdwards while that's useful, that doesn't address my problem: the validation summary element will still be invalid (and have the The scenario I'm thinking of is that I may have some property errors that I have handled otherwise, but in case I can't, for whatever reason, determine what properties the errors relate to, then I would like to show the validation summary (and only then). With the current behavior, the summary is still shown when the form is invalid, even if I explicitly ask for Do you think this should be a separate issue or is it a scenario that will not be covered by |
@CezarCretu one workaround would be to special-case Am I correct what you'd prefer is for |
Yeah, either generate nothing (which would relate to the original discussion) or not add the It's not hard to get around, but Your
|
Clearing milestone so we'll see it in triage. |
Need to add a CSS class to the outer |
@danroth27 seems odd to have an assigned issue in the Backlog milestone. Should it actually be in RC2? If not, I'll just ignore it 🚶🚶🚶 |
Looking back at this, I believe we will have a couple of fairly quick fixes for this issue once #5209 is fixed. I would appreciate opinions on the following from everyone who has commented above. @Bartmax @DamianEdwards @Eilon and the rest: don't hold back. Fixing #5209 at least means the The remaining work here is to somehow hide the Hiding the If we go for the Again, thoughts appreciated... |
Fixed like -> lack typo. |
As @Eilon said, assigning this to any Doug and moving it into 1.1. |
Offline decision was to have any |
Option 1: (it may have unintended side-effects) Option 2: (no breaking changes) I will go with option2, adding the style to the default templates |
you normally want to hide summary-valid class, so css style is still needed ? |
@Bartmax backing up a bit, note everything already handles
No, it searches using a CSS selector (
CSS classes will still exist. But, going with option 1, there's no need for an additional |
- #2372 - make the `ValidationSummaryTagHelper` behave consistently with `Html.ValidationSummar()`
- #2372 - make the `ValidationSummaryTagHelper` behave consistently with `Html.ValidationSummar()`
If I use the validation summary tag helper with custom code, this get renders even when there's no error. I think validation summary should support (or always behave) like don't render anything if there's no error something like.
<div as-validation-summary-visible="Always|OnError">
The text was updated successfully, but these errors were encountered: