mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-17 20:23:50 +00:00
[UI] Add form submission shortcut (#12328)
- Ctrl + enter submits the form
This commit is contained in:
@@ -17,7 +17,10 @@ export type InvenTreeHotkeyItem = [
|
||||
HotkeyItemOptions?
|
||||
];
|
||||
|
||||
export function useInvenTreeHotkeys(_keys: InvenTreeHotkeyItem[]) {
|
||||
export function useInvenTreeHotkeys(
|
||||
_keys: InvenTreeHotkeyItem[],
|
||||
tagsToIgnore?: string[]
|
||||
) {
|
||||
const keyelems: [string, string][] = _keys.map(([key, description]) => [
|
||||
key,
|
||||
description
|
||||
@@ -29,7 +32,7 @@ export function useInvenTreeHotkeys(_keys: InvenTreeHotkeyItem[]) {
|
||||
HotkeyItemOptions?
|
||||
][] = _keys.map(([key, _, handler, options]) => [key, handler, options]);
|
||||
// Register the hotkeys using the Mantine hook
|
||||
useHotkeys(mappedHotkeys);
|
||||
useHotkeys(mappedHotkeys, tagsToIgnore);
|
||||
|
||||
// register to helper state to store hotkeys
|
||||
// This allows us to display the hotkeys in the UI
|
||||
|
||||
@@ -24,6 +24,7 @@ import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import { Boundary } from '@lib/components/Boundary';
|
||||
import { isTrue } from '@lib/functions/Conversion';
|
||||
import { useInvenTreeHotkeys } from '@lib/functions/Events';
|
||||
import {
|
||||
type NestedDict,
|
||||
constructFormUrl,
|
||||
@@ -599,6 +600,23 @@ export function ApiForm({
|
||||
[props.onFormError]
|
||||
);
|
||||
|
||||
// Submit the form with Ctrl+Enter (Cmd+Enter on Mac) while it is open.
|
||||
// An empty tagsToIgnore list allows the hotkey to fire from within form inputs.
|
||||
useInvenTreeHotkeys(
|
||||
[
|
||||
[
|
||||
'mod+Enter',
|
||||
t`Submit form`,
|
||||
() => {
|
||||
if (!isLoading && (!props.fetchInitialData || isDirty)) {
|
||||
form.handleSubmit(submitForm, onFormError)();
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
[]
|
||||
);
|
||||
|
||||
if (optionsLoading || initialDataQuery.isFetching) {
|
||||
return (
|
||||
<Paper mah={'65vh'}>
|
||||
|
||||
Reference in New Issue
Block a user