impress-org / give-double-the-donation

Integration with Double-the-Donation
GNU General Public License v3.0
0 stars 0 forks source link

fix: separate even listener to avoid duplicate listeners #13

Closed JasonTheAdams closed 3 years ago

JasonTheAdams commented 3 years ago

Resolves #11

Description

On the legacy form there was an issue where the company selection dropdown stopped working if another gateway was selected within the form. The issue behind this was that every time the gateway was changed a new script was sent over which attached and additional listener for when the gateway changed. Since the gateway was never removed, every time the gateway changed another listener was attached and fired. This means the initialization for the DtD plugin was being called every time, which caused issues.

This pulls out the event listener into its own script so that it's only attached once per page, so it only fires one time. This resolved the overlying issue.

As a bonus, I also noticed that IDs were being used to select for input fields. This means that multiple legacy forms on a page could not use this add-on. I went ahead and changed the selector to a class (and tweaked the JS) so it's no longer an issue.

Affects

Legacy and multi-step forms using this add-on.

Pre-review Checklist

Testing Instructions

  1. Create multi-step and legacy forms
  2. Enable this add-on for each form
  3. In each form, try setting a company, changing gateways, and setting it again
  4. In each form, try changing gateways (without setting a company) and then setting the company
JasonTheAdams commented 3 years ago

This was tested by @mathetos, so I'm merging this.