mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Fix bug
Don't add a leading coma when the tag list is empty
This commit is contained in:
@@ -22,7 +22,11 @@ export default class extends Controller {
|
||||
}
|
||||
|
||||
// add to tagList
|
||||
this.tagListTarget.value = this.tagListTarget.value.concat(`,${newTagName}`);
|
||||
if (this.tagListTarget.value == "") {
|
||||
this.tagListTarget.value = newTagName;
|
||||
} else {
|
||||
this.tagListTarget.value = this.tagListTarget.value.concat(`,${newTagName}`);
|
||||
}
|
||||
|
||||
// Create new li component with value
|
||||
const newTagElement = this.templateTarget.content.cloneNode(true);
|
||||
@@ -40,7 +44,7 @@ export default class extends Controller {
|
||||
|
||||
// Remove tag from list
|
||||
const tags = this.tagListTarget.value.split(",");
|
||||
this.tagListTarget.value = tags.filter(tag => tag != tagName).join(",");
|
||||
this.tagListTarget.value = tags.filter((tag) => tag != tagName).join(",");
|
||||
|
||||
// manualy dispatch an Input event so the change gets picked up by the bulk form controller
|
||||
this.tagListTarget.dispatchEvent(new InputEvent("input"));
|
||||
|
||||
@@ -126,6 +126,17 @@ describe("TagListInputController", () => {
|
||||
expect(variant_add_tag.classList).toContain("tag-error");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when no tag yet", () => {
|
||||
it("doesn't include leading comma in hidden tag list input", () => {
|
||||
variant_tag_list.value = "";
|
||||
|
||||
variant_add_tag.value = "latest";
|
||||
variant_add_tag.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter" }));
|
||||
|
||||
expect(variant_tag_list.value).toBe("latest");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeTag", () => {
|
||||
|
||||
Reference in New Issue
Block a user