-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Modal: how to destroy? #1370
Comments
The content of the modal is taken from the modal that is in the DOM. Calling
|
Thanks. I assume that UIkit's modal makes a copy then? I change the contents of '#mymodal' and then call UIkit.modal("#mymodal") again and the old contents show up. |
No, it doesn't create/clone anything in the dom. Only alert/confirm create their own modal. This works for me, I think this is what you need:
|
But modal1 and modal2 are static. Try adding a form field to the html. The second time I opened the modal (while even recreating the html including the form field) did not change, the value was the same as the previous time I opened it. I'll try and add a code sample when I am back home. |
Ah, I see the difference. I have a single template (piece of html) for modals. It has an ID that does not change. See this example I use for adding buttons to a markdown editor to help our writers. <div class="uk-modal" id="our-modal">
<div class="uk-modal-dialog">
<button type="button" class="uk-modal-close uk-close"></button>
<div class="uk-modal-header our-modal-header">
<h3></h3>
</div>
<div class="our-modal-content"></div>
<div class="uk-modal-footer our-modal-buttons uk-text-right">
<button type="button" class="uk-button">Cancel</button>
<button type="button" class="uk-button uk-button-primary">Save</button>
</div>
</div>
</div> This template is not in the DOM when no modal is used, the JS adds it to the DOM as soon as the first modal is requested. Action buttons that add text to an editor all use the same modal but they need different modal contents. The first button shows the modal with an explanation and two text fields for a text and a URL, to add TEXT to the text area. All buttons ask for different things. So I am changing the template (source of the modal) and then call this: UIkit.modal('#our-modal').show(); And although I changed the contents of the template, the old contents were shown. I solved it by |
If you replace the content of your JS-template, you'd have to inject that template again into the modal. |
+1 for this conversation, 2 hours of seeing same modal when same id, or when modal not appearing on 1st click when setting id (from angular scope) |
Had the same problem with AngularJS. The solution is to remove the modal from DOM manually. |
Had the same problem with AngularJS. $scope.$on('$destroy', function(){
UIkit.modal('.my-modal').$destroy(true);
}); |
Happening in Angular2 still. When triggered, the modal element is moved to just before the closing body tag. Works fine while using the compnent, but if user routes to a different component, and then comes back, the modal is appended to the DOM again when clicked. My workaround is to listen for the ActivationStart Router event and manually remove the modal element from the DOM just before navigating away. |
@jsiwek11 This was a very old issue that happened when using old Uikit with old Angular. What version of Uikit do you use with Angular 2? In my modern projects where I used Angular 12+ and Uikit 3 I didn't face this issue. |
Thanks, you're right, I probably should have opened a new issue. It is an old project that I recently resurrected & updated. It originally used v2, but currently running Angular 15.1.4 & uikit@3.16.10 installed. Once I'm finished with this sprint, I'll set up a fresh Angular project and try to reproduce a few of these issues I've found in my project. |
Hi,
To generate different modals (some action buttons require confirmation or input), I build a DOM element (div id="mymodal") in JS and show that using UIkit.modal("#mymodal").
When I want to open another modal from another action button, the contents are the same as from the first time I opened the modal.
I guess I could check for existance of "#mymodal" and replace the contents, but if I could destroy the UIkit.modal and rebuild it, that would be so much easier.
Can this be done?
Thanks,
Jerry
The text was updated successfully, but these errors were encountered: