Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enter does not submit recordedit form #2356

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/input-switch/input-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export type InputFieldProps = {
* The styles attached to the container
*/
styles?: any,
/**
* if true, do not intercept on enter
* by default, we are capturing the "enter" key event and stopping it
*/
allowEnter?: boolean
}


Expand Down Expand Up @@ -97,6 +102,7 @@ const InputField = ({
displayErrors,
containerClasses,
styles,
allowEnter = false,
onClear,
controllerRules,
checkHasValue,
Expand Down Expand Up @@ -154,6 +160,13 @@ const InputField = ({
field.onBlur();
};

// intercept enter key down event and stop it from submitting the form
// input types that we "allowEnter" include:
// - array, markdown, longtext, json, and jsonb
const handleKeyDown = (event: React.KeyboardEvent) => {
if (!allowEnter && event.key === 'Enter') event.preventDefault();
}

/**
* we don't want to show the required error until it's submitted
*/
Expand All @@ -167,7 +180,7 @@ const InputField = ({
}

return (
<div className={`${containerClasses} input-switch-container-${makeSafeIdAttr(name)}`} style={styles}>
<div className={`${containerClasses} input-switch-container-${makeSafeIdAttr(name)}`} style={styles} onKeyDown={handleKeyDown}>
{typeof children === 'function' ? children(field, onChange, showClear, clearInput, formInput) : children}
{showError && error?.message && <span className='input-switch-error text-danger'>{error.message}</span>}
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/input-switch/input-switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ const InputSwitch = ({
styles={styles}
displayErrors={displayErrors}
placeholder={placeholder as string}
allowEnter={true}
/>;
case 'popup-select':
if (!columnModel) {
Expand Down Expand Up @@ -344,6 +345,7 @@ const InputSwitch = ({
styles={styles}
displayErrors={displayErrors}
placeholder={placeholder as string}
allowEnter={true}
/>;
case 'json':
case 'jsonb':
Expand All @@ -359,6 +361,7 @@ const InputSwitch = ({
styles={styles}
displayErrors={displayErrors}
placeholder={placeholder as string}
allowEnter={true}
/>;
case 'color':
return <ColorField
Expand Down
Loading