Skip to content
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

296 - Refactor show/hide 'other' college field #310

Merged
merged 2 commits into from
Jan 29, 2024

Conversation

Janell-Huyck
Copy link
Contributor

@Janell-Huyck Janell-Huyck commented Nov 20, 2023

Fixes #296

Refactor of setupOtherCollegeCheckbox Function for Dynamic Form Interaction

Overview

This pull request introduces a refactor of the setupOtherCollegeCheckbox function. The refactor enhances the interaction with the "Other College" checkbox and related text field in our forms, specifically on the edit and new pages. The changes improve the code's readability and functionality, ensuring a more intuitive user experience.

Key Changes

Integration with Turbolinks:

The function is now explicitly executed only when the Turbolinks load event is triggered and on specific pages ("/edit" and "/new"). This ensures the code runs only in the relevant context, improving performance and preventing unnecessary executions.

Dynamic State Synchronization:

Implemented logic to check the "Other College" checkbox automatically if the corresponding text field has a pre-filled value. This is particularly useful in edit forms, ensuring that the state of the checkbox correctly reflects the existing data.

Visibility Control of the Text Field:

Adjusted the code to show or hide the "Other College" text field based on the state of the checkbox. This makes the form more dynamic and responsive to user input, improving the overall user experience.

Introduction of tempStorage for State Preservation:

Added a tempStorage property to the text field element to store its value temporarily. This allows for the text field's content to be preserved and restored if the checkbox is toggled, preventing data loss during user interaction.

Refined Event Handling:

Replaced inline event handling with a more robust event listener attached to the checkbox. This approach follows best practices for event handling in JavaScript and enhances maintainability.

Move repeated College fields and logic to its own partial

Each of the publication types' forms repeated the block of college selection and the "other" college field. I took this PR as an opportunity to move this block into a partial to DRY the code up a bit and to make future maintenance easier. It will also place the Other College selection field in a consistent place in each of the publication types.

@Janell-Huyck Janell-Huyck added the javascript Pull requests that update Javascript code label Nov 27, 2023
@scherztc scherztc self-assigned this Dec 5, 2023
@Janell-Huyck Janell-Huyck force-pushed the refactor-296-show-hide-other-college-field-refactor branch from 4a9220f to c0ae8dd Compare December 6, 2023 22:46
@Janell-Huyck Janell-Huyck force-pushed the refactor-296-show-hide-other-college-field-refactor branch from c0ae8dd to a1b2dbf Compare January 24, 2024 22:15
@Janell-Huyck Janell-Huyck force-pushed the refactor-296-show-hide-other-college-field-refactor branch from 8772650 to 714cc22 Compare January 29, 2024 20:45
@scherztc scherztc merged commit ad46323 into qa Jan 29, 2024
2 checks passed
@scherztc scherztc deleted the refactor-296-show-hide-other-college-field-refactor branch January 29, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor the "other" field manipulation code for clarity
2 participants