[v1] What's the equivalent for requestIntent(form, { value: 'submit' }) #441
-
Hi everyone ! Congrats on the release, I like the new APIs ! I was in the process of migrating, but got stuck migrating code using Has this feature been removed ? Or has it been replaced by something else ? Thanks ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
In v1, we internalize the conform intent to avoid ambiguity with normal intent buttons. What you need can be a submit button with your preferred name like const schema = z.object({
intent: z.enum(['submit', 'or', 'anything']),
// ...
});
export async function action({ request }) {
const formData = await request.formData();
const submission = parseWithZod(formData, { schema });
if (submission.status !== 'success') {
return submission.reply();
}
switch (submission.value.intent) {
case 'submit':
// ...
break;
case 'or':
// ...
break;
case 'anything':
// ...
break;
}
// ....
}
export default function Example() {
const [form, fields] = useForm();
const submitButtonRef = useRef<HTMLButtonElement>(null);
return (
<Form
onChange={() => {
// Click on the submit button to trigger save
submitButtonRef.current?.click();
}}
>
<button name="intent" value="submit" ref={submitButtonRef}>Save</button>
</Form>
);
} |
Beta Was this translation helpful? Give feedback.
That's also what Conform is using internally if the API is available. The only downside of form.requestSubmit() is slightly lower percentage (~93%) in terms of browser support comparing to element.click() (~97%).