Skip to content

Refactored corporate-member-join.js #2043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adamzap
Copy link
Member

@adamzap adamzap commented Apr 19, 2025

  • Stopped using jQuery
  • Moved refactored code to djangoproject.js
  • Reused membership level data between event handlers

This code affects two fields on the corporate member page:

image

- Stopped using jQuery
- Moved refactored code to `djangoproject.js`
- Reused membership level data between event handlers
const level_el = form_el.querySelector('#id_membership_level');
const levels = [-Infinity, 2000, 5000, 12500, 30000, 100000];

amount_el.addEventListener('change', function () {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many ways to implement the functionality for this handler, but this seemed to be the simplest to me.

value = i;
}

level_el.value = value || '';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty string sets the select back to the default selection.

});

level_el.addEventListener('change', function () {
amount_el.value = this.value ? levels[Number(this.value)] : '';
Copy link
Member Author

@adamzap adamzap Apr 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty string sets the select back to the default selection.

Also, I don't think the Number conversion is strictly necessary here, but I using a string index for an array feels wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants