question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<b-modal> @change event not triggering if the modal visible closed immediately

See original GitHub issue

Describe the bug

There is a changed behavior in <b-modal> after the release of v2.0.0-rc.12 and perhaps specifically because of this PR.

When we need to directly hide the modal on @change event, it was working before. For example:

(note: You can try this script on the modal example

<template>
  <div>
    <b-button @click="modalShow = true">Open Modal {{modalShow}}</b-button>
    <b-modal :visible="modalShow" @change="modalShow = false">Hello From Modal!</b-modal>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        modalShow: false
      }
    }
  }
</script>

On first click the button, it will set the modalShow to true and directly back to false. On the second click and next after, it will set modalShow to true and never set back to false anymore.

By right, the modalShow should always be false whenever we click the button, because when the modal show and @change event triggered, it will directly set to false. This is working back in v2.0.0-rc.11 before.

I found out the culprit is because on the 2nd click, the flag is_closing is still true therefore it prevents the show function from running further.

Screen Shot 2019-04-17 at 2 47 57 PM

Steps to reproduce the bug

  1. Copy paste the script I add above to the modal example
  2. Click the “Open Modal” button.
  3. On first click, the showModal flag will be set back to false
  4. On second click, the showModal will be set to true and never be false anymore.

Expected behavior

The flag showModal should be back to false, as the @change event should be triggered.

Versions

Libraries:

  • BootstrapVue: 2.0.0-rc.12
  • Bootstrap: 4.3.1
  • Vue: 2.6.0

Environment:

  • Device: Mac
  • OS: MacOS
  • Browser: Chrome
  • Version: 73

Demo link

Try the script pasted above in the bootstrap vue website modal example

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
chenxeedcommented, Apr 18, 2019

@tmorehouse thank you for the thoughts!

The reason why I put the prevention on @change is because the change event is the one that handles the v-model therefore it is the one that will run $emit('change', visible) for the parent to listen. It was working before that’s why I reported this as a bug.

I would agree and follow your suggestion that in @change event we should only handle the v-model event.

As for your suggestion above, I tried this script on the bootstrap-vue example:

<template>
  <div>
    <b-button @click="modalShow = true">Open Modal {{modalShow}}</b-button>

    <b-modal :visible="modalShow" @show="onShow">Hello From Modal!</b-modal>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        modalShow: false
      }
    },
    methods: {
      onShow(bvModalevt) {
        bvModalEvt.preventDefault()
      }
    }
  }
</script>

The onShow event doesn’t stop the modal from appearing. Is this the expected output?

0reactions
tmorehousecommented, Apr 18, 2019

Hmmm we might not be resetting the v-model on prevent.

The best way to prevent the button from opening the modal would be to disable the button.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle Bootstrap modal hide event in Vue JS - Stack Overflow
Bootstrap uses JQuery to trigger the custom event hidden.bs.modal so it is not easily caught by Vue (which I believe uses native events...
Read more >
Modal | Components - BootstrapVue
Modals, when visible, are rendered appended to the <body> element. The placement of the <b-modal> component will not affect layout, as it always...
Read more >
Modal - Bootstrap
Modals are built with HTML, CSS, and JavaScript. · Clicking on the modal “backdrop” will automatically close the modal. · Bootstrap only supports...
Read more >
Modal Events - hide.bs.modal - W3Schools Tryit Editor
bs.modal event occurs modal is about to be hidden. Click the "Hide Modal" button to trigger the hide method (which will trigger the...
Read more >
How to close model from a button using vue.js - GeeksforGeeks
js you can use the click event i.e. @click to trigger change in modal visibility. So, whenever the close button is pressed the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found