Skip to content

fix: validate color input and prevent invalid hex values#447

Merged
surajshetty3416 merged 5 commits intofrappe:developfrom
Vibhuti410:color-input-validation
Dec 26, 2025
Merged

fix: validate color input and prevent invalid hex values#447
surajshetty3416 merged 5 commits intofrappe:developfrom
Vibhuti410:color-input-validation

Conversation

@Vibhuti410
Copy link
Collaborator

Issue:

The color input field accepted invalid values like incorrect or incomplete hex values. On pressing Enter, the invalid values were accepted without any verification feedback.

Solution:

Added validation for color input field.
Now it shows visual error if invalid values are entered.
Prevents appplying invalid hex values.

After:

After.1.mp4

Note: This PR focuses on hex and functional color formats. Support for named CSS colors (e.g 'red' , 'black') can be added as separate follow up improvement.

Closes #434

Copy link
Member

@surajshetty3416 surajshetty3416 left a comment

Choose a reason for hiding this comment

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

@Vibhuti410 Instead of showing red borders for invalid value, I would suggest not letting set any invalid value (and retain the previous value) till the user set a valid value.

With this, we can also auto strip extra hashes automatically if rest of the value looks valid. This IMO will give better and intuitive UX.

@Vibhuti410
Copy link
Collaborator Author

@surajshetty3416 Thank you for your suggestion.

The current logic already keeps the last valid input and doesn't apply invalid changes. I agree the changes you suggested would result in a more intuitive UX. I will look into it and try to make the required changes.

@Vibhuti410
Copy link
Collaborator Author

Vibhuti410 commented Dec 19, 2025

@surajshetty3416 As per your suggestion I have updated the implementation to auto-strip the extra hashes if the rest of the input is valid. It also avoids applying invalid values along with visually highlighting the incorrect input with red border and retains the last valid input color.

Demo:

demo.1.mp4

@Vibhuti410
Copy link
Collaborator Author

@surajshetty3416 I have pushed an update as per your suggestion.

Please let me know if this looks good or if you'd like any further changes.

@surajshetty3416
Copy link
Member

@Vibhuti410 I don't prefer the red outline in the inputs... as suggested previously, let's reset the input (with the old value) on blur if the user inputs an invalid value. Your other fix of trimming extra "#"s seems fine.

@Vibhuti410
Copy link
Collaborator Author

@surajshetty3416

updated.1.mp4

Removed the red outline. When an invalid input is entered, it is not applied and the last valid color is retained. The auto-strip extra hashes logic remains unchanged.

- Move inline handler out of the template into a dedicated handleColorUpdate method
- fix formatting
@surajshetty3416 surajshetty3416 merged commit 8a4567d into frappe:develop Dec 26, 2025
1 check passed
@github-actions
Copy link

🎉 This PR is included in version 1.22.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Color field accepts incorrect hex values

2 participants