8000 Submit a <b-form> when a key is pressed · Issue #913 · bootstrap-vue-next/bootstrap-vue-next · GitHub
[go: up one dir, main page]

Skip to content
Submit a <b-form> when a key is pressed #913
Closed
@VividLemon

Description

@VividLemon

Discussed in https://github.com/bootstrap-vue/bootstrap-vue-next/discussions/877

Originally posted by loetermann January 14, 2023
Hi,
so I have a with a sumbit button. Some input fields are required. I would like to also submit the form when the user presses Ctrl+S. I would like the to do the same input validation the submit button triggers.
Is there any way to get this done? I fear not, as the Components do not defineExpose their functions, right?

<script setup lang="ts">

const inputForm = ref(null);

function onKeyDown(e: KeyboardEvent) {
  if ((e.ctrlKey || e.metaKey) && e.key === 's') {
    e.preventDefault();
    onSave(); // <-- This does no validate if the required fields are filled
   inputForm.value?.submit() // <-- This function does not exist. Any other option to trigger the sumbit here?
  }
}
</script>

<template>
  <b-form ref="inputForm" @submit="onSave">...</b-form>
</template>
```</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstale-exemptUse this to prevent auto-stalling of an issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0