Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent closing Toast when closing Modal in BootstrapVue

I would like to prevent closing Toast when closing Modal in BootstrapVue.

Scenario:

  1. Open the Modal and Toast on the page
  2. Close the modal
  3. then Modal and Toast closed at the same time

Question: how to keep Toast stays

    created() {
       this.$bvModal.show('modal-form-id')
       const errorToaster = {
          title: 'Success',
          toaster: 'b-toaster-top-center',
          variant: 'success'
        }
       this.$bvToast.toast('Success', errorToaster)
    },
    methods: {
       closeModal() {
         this.$bvModal.hide('modal-form-id')
       }
    }

    
like image 943
CHHUM Sina Avatar asked Jul 13 '20 11:07

CHHUM Sina


People also ask

How do you stop modal from closing when clicking outside Vue?

You can prevent closing of modal dialog by setting the beforeClose event argument cancel value to true.

How do I close modal after submitting Vue?

To close a modal using vue. js you can use the click event i.e. @click to trigger change in modal visibility. So, whenever the close button is pressed the @click method will trigger the function associated with the action ( here, hiding the modal ).

How do I close a bootstrap Vue modal?

<b-modal> supports close on ESC (enabled by default), close on backdrop click (enabled by default), and the X close button in the header (enabled by default). These features may be disabled by setting the props no-close-on-esc , no-close-on-backdrop , and hide-header-close respectively.

What is bvToast?

$bvToast. toast() method to generate on demand toasts. The method accepts two arguments: message : the content of the toast body (either a string, or an array of VNodes ).


3 Answers

Try to add $root.

this.$root.$bvToast.toast("Success", errorToaster);
like image 74
Sidara KEO Avatar answered Sep 29 '22 08:09

Sidara KEO


In you errorToaster add this no-auto-hide: true.

Example:

const errorToaster = {
    title: 'Success',
    toaster: 'b-toaster-top-center',
    variant: 'success',
    'no-auto-hide': true,
}
like image 33
Rafik Farhad Avatar answered Sep 29 '22 07:09

Rafik Farhad


Toast has auto-hide-delay property - the number of milliseconds before the toast auto dismisses itself, so it closes with no connection to modal closing.

add to your code:

const errorToaster = {
      title: 'Success',
      toaster: 'b-toaster-top-center',
      variant: 'success',
      autoHideDelay: // default is 5000,
      noAutoHide: true // in order to stay it open forever
 }
like image 41
Nan fish Avatar answered Sep 29 '22 07:09

Nan fish