FIX: Fix broken translation in tags input field objects setting editor (#26340)

Why this change?

When a property of `type: tags` is required, we should be displaying the
"at least 1 tag is required" validation error message when there are no
tags selected in the `TagChooser` compoment. However, we were passing
`this.min` as the `count` attribute when generating the translation
string which is incorrect as `this.min` is not always set.
This commit is contained in:
Alan Guo Xiang Tan 2024-03-25 16:06:32 +08:00 committed by GitHub
parent 83ca1fd134
commit 8a6e43a3d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 13 deletions

View File

@ -36,8 +36,8 @@ export default class SchemaThemeSettingTypeTags extends Component {
(this.min && this.value.length < this.min) ||
(this.required && (!this.value || this.value.length === 0))
) {
return I18n.t("admin.customize.theme.schema.fields.tags.at_least_tag", {
count: this.min,
return I18n.t("admin.customize.theme.schema.fields.tags.at_least", {
count: this.min || 1,
});
}
}

View File

@ -736,6 +736,10 @@ module(
required_tags: {
type: "tags",
required: true,
},
required_tags_with_validations: {
type: "tags",
required: true,
validations: {
min: 2,
max: 3,
@ -745,7 +749,8 @@ module(
},
value: [
{
required_tags: ["gazelle", "cat"],
required_tags: ["gazelle"],
required_tags_with_validations: ["gazelle", "cat"],
},
],
});
@ -756,8 +761,8 @@ module(
const inputFields = new InputFieldsFromDOM();
const tagSelector = selectKit(
`${inputFields.fields.required_tags.selector} .select-kit`
let tagSelector = selectKit(
`${inputFields.fields.required_tags_with_validations.selector} .select-kit`
);
assert.strictEqual(tagSelector.header().value(), "gazelle,cat");
@ -778,8 +783,10 @@ module(
inputFields.refresh();
assert.dom(inputFields.fields.required_tags.errorElement).hasText(
I18n.t("admin.customize.theme.schema.fields.tags.at_least_tag", {
assert
.dom(inputFields.fields.required_tags_with_validations.errorElement)
.hasText(
I18n.t("admin.customize.theme.schema.fields.tags.at_least", {
count: 2,
})
);
@ -791,11 +798,29 @@ module(
inputFields.refresh();
assert.dom(inputFields.fields.required_tags.errorElement).hasText(
I18n.t("admin.customize.theme.schema.fields.tags.at_least_tag", {
assert
.dom(inputFields.fields.required_tags_with_validations.errorElement)
.hasText(
I18n.t("admin.customize.theme.schema.fields.tags.at_least", {
count: 2,
})
);
tagSelector = selectKit(
`${inputFields.fields.required_tags.selector} .select-kit`
);
await tagSelector.expand();
await tagSelector.deselectItemByName("gazelle");
await tagSelector.collapse();
inputFields.refresh();
assert.dom(inputFields.fields.required_tags.errorElement).hasText(
I18n.t("admin.customize.theme.schema.fields.tags.at_least", {
count: 1,
})
);
});
test("input fields of type group", async function (assert) {

View File

@ -5653,7 +5653,7 @@ en:
fields:
required: "*required"
tags:
at_least_tag:
at_least:
one: "at least %{count} tag is required"
other: "at least %{count} tags are required"
string: