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.

Message box input press `Enter` to confirm

See original GitHub issue

Vue: v2.6.12
BootstrapVue: v2.21.2

Instead of manually clicking OK, how to press Enter to confirm?

let text
this.$bvModal.msgBoxConfirm(<input vModel={text} />)

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Hiwscommented, Mar 25, 2021

@Hiws Also, how to prevent closing on clicking OK when using message boxes?

Listen for the hide event on root. this.$root.$on("bv::modal::hide", someMethod); When the method is called it’s passed a bvEvent parameter, which you can call preventDefault() on if you dont want to hide the modal. It also includes the ID of the modal which was closed, and which trigger was used.

Here’s a rough example. https://codepen.io/Hiws/pen/QWdjojm

1reaction
Hiwscommented, Mar 25, 2021

You can supply an id in the options object, and then use this.$bvModal.hide('my-modal-id') inside a keyup event on your input, which looks for the press of the Enter key (keycode 13). You can then call a separate method which handles your logic and hide your modal.

Example

https://codepen.io/Hiws/pen/ExZVExB


I’ve also opened a PR (https://github.com/bootstrap-vue/bootstrap-vue/pull/6523), which adds an optional parameter to the $bvModal.hide method, which allows you to supply a trigger. By supplying the trigger of ok, it will close the modal as if the OK button was pressed.

For example: $bvModal.hide('my-modal-id', 'ok'). This would work with cancel, backdrop and other triggers as well, even custom ones.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BootstrapVue message box input press `Enter` to confirm
I've figured this out: const modalId = 'modalId' const ok = () => this.$bvModal.hide(modalId) let text this.$bvModal.msgBoxConfirm(<input ...
Read more >
How to Detect the Enter Key Press in a Text Input Field Using ...
Answer: Use the keypress event. To check whether a user has pressed Enter key while on specific input, you can use the keypress...
Read more >
How To Use the ENTER Key from Edit Controls in a Dialog Box
There are a few ways to enable the use of the ENTER key to move between edit controls. One method is to make...
Read more >
Interaction: alert, prompt, confirm
It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel. title: The text to...
Read more >
Window.confirm() - Web APIs - MDN Web Docs
window.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels ...
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