Nested modal works perfectly #349
joshjohner
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
Do you have an example of this? It sounds interesting but I can't totally follow what you have created. If you can show as an example, I am very interested 😃. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So I accidently implemented something that was EXTREMELY useful. I'm not sure if it was supposed to work this way, is a "duh of course that works because...." or what.... but...
I created a generic "SaveCancelModal" component with contains a DataAnnotationsValidator and ValidationSummary, displays the child content and a Save/Cancel button group inside an edit form. The "SaveCancelModal" contains the BlazoredModalInstance (and a IModalService to display a nested "Discard Changes" modal on cancel).
Then when I need an edit form for a specific object type, I create an EditObjectModal component, which contains a SaveCancelModal component, but is not bound directly to a BlazoredModalInstance, and supplies the @ChildContent of the SaveCancelModal with the edit fields and interacts with the repository.
When I call modal.Show() it is able to find the BlazoredModalInstance in the nested SaveCancelModal, and everything just runs with NO additional work. And by having my Objects that need saving implement an interface to determine if they are new or edit, the SaveCancelModal.razor.cs can be of type where TItem : Interface and the bulk of my logic is contained in the SaveCancelModal, which only needs EventCallback for CreateItem and UpdateItem. Meaning the EditObjectModal only has to contain the ChildContent, a reference to the repository, a way to populate the form on initialization and callback functions for CreateObject and EditObject.
Beta Was this translation helpful? Give feedback.
All reactions