question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Submit programmatically

See original GitHub issue

Is it possible to trigger EmailEditorProvider.onSubmit programmatically (e.g. in a custom hook) given this modified layout from the example?

<EmailEditorProvider
  autoComplete
  data={template}
  ...
  onSubmit={saveTemplate}
>
  {() => <EmailEditor height={"100vh"} />}
</EmailEditorProvider>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
m-Ryancommented, Nov 19, 2021

You can not call useForm out of context provider.

export function Editor(): JSX.Element {
  const [template, mergeTags] = useTemplateData();
  const [buttonRef, saveTemplate] = useTemplateSaving();


  if (!template) {
    return null;
  }

  return (
    <EmailEditorProvider
      autoComplete
      data={template}
      mergeTags={mergeTags}
      onSubmit={saveTemplate}
    >
      {(_, { submit }) => (
        <>
          <EmailEditor height={"100vh"} />
          <button ref={buttonRef} hidden onClick={submit}></button>
          <OtherComponent />
        </>
      )}
    </EmailEditorProvider>
  );
}

function OtherComponent() {
  const { submit } = useForm(); 
}

1reaction
m-Ryancommented, Nov 19, 2021

EmailEditorProvider.onSubmit === react-final-form.onSubmit;

try this

 import { useForm } from 'react-final-form';
 
 const {  submit } = useForm();

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Submit a Form Using JavaScript
Generally, a form is submitted when the user presses a submit button. However, sometimes, you may need to submit the form programmatically using...
Read more >
Cannot programmatically submit form [duplicate]
The problem is that you have a field ( HTMLInputElement ) with name submit in the form. That's why document.getElementById('ss-form').submit ...
Read more >
HTMLFormElement.submit() - Web APIs | MDN
The HTMLFormElement.submit() method submits a given <form> . This method is similar, but not identical to, activating a form's submit ...
Read more >
.submit() | jQuery API Documentation
The submit event is sent to an element when the user is attempting to submit a form. It can only be attached to...
Read more >
How do you submit a form programmatically in Blazor?
You can submit a Blazor form programmatically by using EditContent validation. In the following example, a keypress event function triggers ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found