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

Ensure Consistent Category Colors #1722

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

JLambertazzo
Copy link
Contributor

@JLambertazzo JLambertazzo commented Jan 28, 2025

Closes #1668

Note

Was not able to accomplish reactivity in this PR. Disabling of other colors, in addition to displaying the error message, only shows up after a failed attempt to create the category.

Approach

  • Added validation in the category.rb model which displays the message below when trying to select a color different from the parent category
  • Grayed-out and disabled other colors when validation fails to reflect validation rule
    Validation result. Invalid colors are greyed out and disabled. Error message is displayed in red
  • Once correct color is selected, category can be created
    Successful result after selecting a valid color

@zachgoll
Copy link
Collaborator

@JLambertazzo just an idea here—what if we used a simple Stimulus controller to hide the color picker entirely if the parent category field is populated, then on the backend, we simply use our internal logic to assign the parent color to the subcategory?

cc @justinfar in case you had other ideas here.

@JLambertazzo JLambertazzo marked this pull request as ready for review January 30, 2025 12:59
@JLambertazzo
Copy link
Contributor Author

@JLambertazzo just an idea here—what if we used a simple Stimulus controller to hide the color picker entirely if the parent category field is populated, then on the backend, we simply use our internal logic to assign the parent color to the subcategory?

This worked really well! Here are the results:
Selection hides when parent is selected


Created subcategory is forced to have parent color

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.

Improvement: Add validation so that subcategories are always the same color as the parent
2 participants