Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

How to run a function every time the modal opens?


Hello!

I'm using Metronic Vue version 8.1.8.

On the page https://preview.keenthemes.com/metronic8/vue/demo7/#/apps/customers/customers-listing, there is a button called "Add Customer". When you click on it, a modal opens with a form.

This modal is located inside the component /src/components/modals/forms/AddCustomerModal.vue.

I would like assistance in understanding how I can configure this component to execute a function every time the modal opens.

What I actually need is to reset the form every time the modal opens.

I tried by adding @click to the button, but since I want to manipulate the form, I believe it needs to be configured within the component itself and based on the event.

Thank you for your attention.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi Fernando,

You can trigger code every time model is open by using bootstrap "show.bs.modal" event.

Just add the following code into your <stronng>/src/components/modals/forms/AddCustomerModal.vue.</a>

onMounted(() => {
if (addCustomerModalRef.value) {
addCustomerModalRef.value.addEventListener(
"show.bs.modal",
function (event: Event) {
console.log(event);
}
);
}
});


For more info, please check Bootstrap 5 Modal documentation.
https://getbootstrap.com/docs/5.2/components/modal/

Regards,
Lauris Stepanovs,
Keenthemes Support Team



It worked. Thank you very much.



Hi Fernando,

Glad to hear that. All the best with your project!

Please let us know if you have any further questions on this topic or anything else.

Regards,
Lauris Stepanovs,
Keenthemes Support Team


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(