4

I have created a modal with some dynamic content (input fields) and a save button to save input field data in database and I'm opening that modal on a button click.

Now when I fill all the input fields and save it or when I close the modal by pressing the "X" icon at top right without saving, the data in the modal persists and doesn't get cleared when I reopen that modal using button click.

Is there a way to completely destroy that modal and create a fresh one on each button click?

1
  • share your modal open js or jquery code and your form as well Commented Dec 10, 2016 at 6:33

1 Answer 1

1

I dont think there is any destroy method in modal.js. If you want to clear input, reload the modal or whatever you want to do, you can implement closed event and do your thing when the modal is closing.

http://devdocs.magento.com/guides/v2.0/javascript-dev-guide/widgets/widget_modal.html#modal_closed

myModal.modal({
                    innerScroll: true,
                    modalClass: '_my-box',
                    buttons: [],
                    closed: function () {
                        alert('cleaning up');
                    }
                }).trigger('openModal');

The modals are based on Ui widget and that should implement _destroy() method that could also help you if the above doesnt work for any reason.

https://api.jqueryui.com/jquery.widget/#method-_destroy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.