-
-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Hi there; I was just wondering if there's any recommended patterns handling form submissions with superglue v2 so that a form's submit button can be disabled programatically on a per-form basis depending on where it's posting to? The intent is to ensure on a slow browser connection, the user doesn't continue to send additional 'submit' button press whilst the client is still awaiting the response of the first submission.
i.e. Something similar to the behavior in stimulus:
During a submission, Turbo Drive will set the “submitter” element’s disabled attribute when the submission begins, then remove the attribute after the submission ends. When submitting a
element, browsers will treat the or element that initiated the submission as the submitter. To submit a element programmatically, invoke the HTMLFormElement.requestSubmit() method and pass an or element as an optional parameter.
Or mocked:
const [isFormOneLoading, ...] = useFormState(formOne);
const [isFormTwoLoading, ...] = useFormState(formTwo);
return (
<>
<Form {...formOne} extras={extras} data-sg-remote>
<SubmitButton loading={isFormOneLoading} />
</Form>
<Form {...formTwo} extras={extras} data-sg-remote>
<SubmitButton loading={isFormTwoLoading} />
</Form>
<>
)This seems like something that can be built by overriding the onSubmit attribute on the form, stopping propagation, and trying to reuse superglue's ujsHandlers and awaiting the result similar to the infinite scroll request - but that seems like it's reaching into the wrong layers, but let me know your thoughts 💯