Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When used with DynamicComponent(.Net 6 feature) validation messages are getting duplicated #93

Open
umeshvenkat opened this issue Oct 8, 2021 · 7 comments
Labels
Bug Something isn't working Needs: Investigation The issues needs investigation before implementing
Milestone

Comments

@umeshvenkat
Copy link

I am trying to build a Wizard feature using DynamicComponent(.Net 6 feature).
When we navigate to next page and comeback using previous button and clear the text of some control and make to validate the form, validation fires. As many times we repeat this, validation messages repeats as shown in below image. Expectation is to show one message.
Complete code is available in following repo.

https://github.com/umeshvenkat/DynamicComponentFluentValidation

This is how repetitive messages are displayed.

image

@umeshvenkat umeshvenkat added Question Question about this project Triage Issue needs to be triaged labels Oct 8, 2021
@umeshvenkat
Copy link
Author

I think its happening because multiple validators getting attached when we traverse using next and previous button. Is there a way to add validator only once.

Same setup works fine with Data Annotation Validators without duplicating validation messages.

@chrissainty chrissainty added Needs: Investigation The issues needs investigation before implementing and removed Triage Issue needs to be triaged labels Oct 22, 2021
@chrissainty
Copy link
Member

Thanks for raising this @umeshvenkat. I've haven't done any work with the Dynamic component so I'm not sure what kind of effect it would have. It seems the validation message store isn't being cleared for some reason when a new validation call is made. I think this will take me some time to get my head around.

@chrissainty chrissainty added this to the vNext milestone Jan 21, 2022
@chrissainty chrissainty added Bug Something isn't working and removed Question Question about this project labels Jan 21, 2022
@alexx-grand
Copy link

It looks like my #155 issue

@DanRogers99
Copy link

Hi, @chrissainty are you any closer to finding a fix or work around for this?

@ddudda174
Copy link

There is another problem due to the reuse of the same EditContext, for example when some components with conditions are shown or hidden.

I have created a modal window which has two EditForm components. These are each separated by an If block and can be shown or hidden with a ToggleButton. The first form uses its own EditContext while the second references a simple class.

Now when I edit a field in the first form it is initially shown as valid, but if I delete the entry so that the field is marked as edited then the NotEmpty rule kicks in and shows this red with the appropriate error message. Now I switch to the second form and right back while the error message was still displayed. Right when I call the first form again, the error message and the red border around the text field remains. If I now enter a value and the field would thus be valid, however, the display remains unchanged (red border + error message). If I delete the value again, I get a second error message. This process can be repeated as often as desired and each time a new error message is added. With the second form, which is initialized with a model, this problem does not exist.

Unfortunately I could not find a suitable way to reset the error messages when switching forms. Neither deleting the error messages (MessageStore), nor deleting the attached events or further functions from the validation or the EditContext (Validate, Notify(...), MarkAsUnmodified, etc.) brought a success. However, the error messages are cleared and the events are detached.

It seems to have something to do with the FieldState, as far as I have seen it remains and certainly contains the still displayed error message, the rest of the form is reset correctly and then just generates a new error message in addition to the old state. As a workaround, recreating the EditContext completely new was the only solution so far.

@DanRogers99
Copy link

Hi @ddudda174

Thanks for your investigation.

You said as a workaround, recreating the EditContext completely new was the only solution so far. Can you give an example of how you did this?

Many thanks

@ddudda174
Copy link

ddudda174 commented Jan 5, 2023

@DanRogers99 Well i simply set "_myContext = new EditContext(model)" to reset it while changing between the Tabs. Like this line here.

I haven't tested the stuff from another issue (#168) in here which seems related to this problem, but there might be some other solutions instead of setting a complete new EditContext after the view changed.

According to an answer on stackoverflow the better approach would be to clear the messages from the messagestore for a specific field instead of clearing it for everything, which not seems to work properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Needs: Investigation The issues needs investigation before implementing
Projects
None yet
Development

No branches or pull requests

5 participants