<Submit>
The <Submit>
component is a shortcut for an <input type="submit" />
element.
The disableOnError
props needs the context to be set.
Props
<Submit>
takes the following props:
Property | Type | Default | Description |
---|---|---|---|
disableOnError | boolean | Disable the submit button when the form is not valid | |
...rest | unknown[] | All props are forwarded to the <input> element |
Usage
0
import type { FormEvent } from 'react';
import type { IProps } from '../types';
import {
FormProvider,
type IFormValues,
Submit,
useForm,
} from '@per-form/react';
export default function Demo(props: IProps) {
function handleSubmit(_e: FormEvent<HTMLFormElement>, values: IFormValues) {
console.log(values);
}
const { formProps, ...context } = useForm({
...props,
onSubmit: handleSubmit,
});
const { errors } = context;
return (
<FormProvider {...context}>
<form {...formProps}>
<input name="text" required />
{errors.all.text && <div className="error">{errors.all.text}</div>}
<Submit disableOnError />
</form>
</FormProvider>
);
}