FIX: Validate email_accent_bg_color color (#13778)

Using an invalid value was allowed. This commit tries to automatically
fix the color by adding missing # symbol or will show an error to the
user if it is not possible and it is not a CSS color either.
This commit is contained in:
Bianca Nenciu
2021-07-22 17:42:47 +03:00
committed by GitHub
parent 3667cc6447
commit 18c32a809b
5 changed files with 88 additions and 4 deletions

View File

@@ -22,9 +22,21 @@ export default Component.extend({
return this.onlyHex ? 6 : null;
}),
normalize(color) {
if (/^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(color)) {
if (!color.startsWith("#")) {
color = "#" + color;
}
}
return color;
},
@action
onHexInput(color) {
this.attrs.onChangeColor && this.attrs.onChangeColor(color || "");
if (this.attrs.onChangeColor) {
this.attrs.onChangeColor(this.normalize(color || ""));
}
},
@observes("hexValue", "brightnessValue", "valid")
@@ -32,7 +44,9 @@ export default Component.extend({
const hex = this.hexValue;
let text = this.element.querySelector("input.hex-input");
this.attrs.onChangeColor && this.attrs.onChangeColor(hex);
if (this.attrs.onChangeColor) {
this.attrs.onChangeColor(this.normalize(hex));
}
if (this.valid) {
this.styleSelection &&