feat(promoted_attributes): support removing color

This commit is contained in:
Elian Doran 2025-07-26 09:49:32 +03:00
parent b29781b614
commit d23230df68
No known key found for this signature in database
2 changed files with 25 additions and 2 deletions

View File

@ -841,7 +841,8 @@
"unknown_label_type": "Unknown label type '{{type}}'",
"unknown_attribute_type": "Unknown attribute type '{{type}}'",
"add_new_attribute": "Add new attribute",
"remove_this_attribute": "Remove this attribute"
"remove_this_attribute": "Remove this attribute",
"remove_color": "Remove the color label"
},
"script_executor": {
"query": "Query",

View File

@ -272,7 +272,29 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
$input.after($openButton);
} else if (definition.labelType === "color") {
$input.prop("type", "color");
$input.prop("type", "hidden");
const setValue = (color: string, event: JQuery.TriggeredEvent<HTMLElement, undefined, HTMLElement, HTMLElement>) => {
$input.val(color);
event.target = $input[0]; // Set the event target to the main input
this.promotedAttributeChanged(event);
};
// We insert a separate input since the color input does not support empty value.
// This is a workaround to allow clearing the color input.
const $colorInput = $("<input>")
.prop("type", "color")
.prop("value", valueAttr.value ?? "#000000")
.addClass("form-control promoted-attribute-input")
.on("change", e => setValue((e.target as HTMLInputElement).value, e));
$input.after($colorInput);
const $clearButton = $("<span>")
.addClass("input-group-text bx bxs-tag-x")
.prop("title", t("promoted_attributes.remove_color"))
.on("click", e => setValue("", e));
$colorInput.after($clearButton);
} else {
ws.logError(t("promoted_attributes.unknown_label_type", { type: definition.labelType }));
}