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.

Events triggered on multiple forms on the same page

See original GitHub issue

Hi,

I have two forms in the same react component, and the onChange event in both forms are triggered when I change one of the forms. Here is the code:

import { Form } from 'react-formio'

const form1 = {
  components: [
    {
      label: 'Input1',
      type: 'textfield',
      input: true,
      key: 'input1',
    },
  ],
  display: 'form',
  page: 0
}
const form2 = {
  components: [
    {
      label: 'Input2',
      type: 'textfield',
      input: true,
      key: 'input2',
    },
  ],
  display: 'form',
  page: 0
}
class Container extends Component {
  constructor(props) {
    super(props)
  }

  onChange(event, id) {
    console.log('onChange', id)
  }
  render() {
    return (
      <div>
        <Form key='1' form={form1} onChange={(event) => this.onChange(event, '1')} />
        <Form key='2' form={form2} onChange={(event) => this.onChange(event, '2')} />
      </div>
    )
  }
}

export default Container

When I change “input1”, I am expecting to see only one event is triggered, however, two events are triggered and console prints out:

onChange 1
onChange 2

Why is the event for form 2 triggered? I also experience the same issue with the onSubmit event.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
iobuhovcommented, Dec 20, 2018
0reactions
ybocommented, Dec 19, 2018

Thanks! Can you please link the commit or PR to this issue? I would like to know the fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any way to trigger a DOM event for multiple forms at ...
CF7 events bubble up through the document, so you can do something like this, let page = document.querySelector('body'); page.
Read more >
Events triggered on multiple forms on the same page #149
Hi, I have two forms in the same react component, and the onChange event in both forms are triggered when I change one...
Read more >
Multiple forms, same event? Here's how to track each form ...
Solution: We used a Lookup Table variable to give each form a different name, based on its form ID. In the Google analytics...
Read more >
Two Forms, Two Actions, Same Page - PHP - W3Schools Forum
This strategy has led to the following two questions: QUESTION ONE: Under the assumption that one can have only one $_POST variable per...
Read more >
Track Many Forms with One Thank You Page with Google Tag ...
Learn how to track multiple forms with one Thank you page. This guide covers various techniques and explains how to choose the best...
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