Next.js Discord

Discord Forum

Trying to trigger form using useRef and forward Ref

Answered
Crème D’Argent posted this in #help-forum
Open in Discord
Avatar
Crème D’ArgentOP
I yearn to remotely engage this form, either through simulating a button press or utilizing a direct form reference.

https://gist.github.com/hossam1231/2e5e991b2c78a70800ecf10e9bb22a69

https://gist.github.com/hossam1231/21a401f693fc56e01dd0f24e0f61a47e
Answered by sabin
What is the reason for trying to have the submit button outside of the form element? Ideally, we should always place the button within the form.

I think you can achieve this by referencing the form id:

<form id="createIncidentForm">
</form>

<button type="submit" form="createIncidentForm">Create</button>
View full answer

6 Replies

Avatar
What is the reason for trying to have the submit button outside of the form element? Ideally, we should always place the button within the form.

I think you can achieve this by referencing the form id:

<form id="createIncidentForm">
</form>

<button type="submit" form="createIncidentForm">Create</button>
Answer
Avatar
Crème D’ArgentOP
thank you il give this a try
this is because my form element is from within the page however my submit button is within my layout
Avatar
Crème D’ArgentOP
splendid this has worked like a charm thanks a million
ahaha turns out when you skip to react you miss all these handy things like id
Avatar
Haha, yeah, always master the fundamentals 🙂