Hello team, and thank you in advance for taking the time to read my question.
I have run into the problem described in #1642 for a big oneOf
enum with dynamic values I don’t control, in which each item’s “ID” is a number different from it’s “readable name”. I’m trying to use the suggested i18n workaround as I’d like to keep validation for these enum fields (most of them are required and can’t be empty).
I’ve found that when my translator
function runs for the enum’s items the ctx
argument is undefined
. This is a problem because I need to access the uischema
in the context, in order to find the “translation” from ID to readable name. However, when translating the title and description for the control, the ctx
is populated.
Could you please advice on what might be the issue? Pasting example data below. Thank you!
This is my schema:
{
"type": "object",
"properties": {
"enumWithTranslations": {
"title": "A HUGE enum (using i18n for labels)",
"description":
"A choice from a list of options, where readable labels come from translations",
"enum": [
"enum 0",
"enum 1",
"enum 2",
"enum 3",
"enum 4",
"enum 5",
"enum 6",
"enum 7",
"enum 8",
"enum 9",
],
},
},
}
And my UI schema:
{
type: "VerticalLayout",
elements: [
{
"type": "Control",
"scope": "#/properties/enumWithTranslations",
"i18n": "default",
"title#0": "label 0",
"title#1": "label 1",
"title#2": "label 2",
"title#3": "label 3",
"title#4": "label 4",
"title#5": "label 5",
"title#6": "label 6",
"title#7": "label 7",
"title#8": "label 8",
"title#9": "label 9",
},
],
}
So, when I log the arguments received in my translator function for the control’s title
and description
it looks like this
{
"id": "default.label",
"defaultMessage": "A HUGE enum (using i18n for labels)",
"ctx": {
"schema": {
"title": "A HUGE enum (using i18n for labels)",
"description": "A choice from a list of options, where readable labels come from translations",
"enum": [
"enum 0",
"enum 1",
"enum 2",
"enum 3",
"enum 4",
"enum 5",
"enum 6",
"enum 7",
"enum 8",
"enum 9"
]
},
"uischema": {
"type": "Control",
"scope": "#/properties/enumWithTranslations",
"i18n": "default",
"title#0": "label 0",
"title#1": "label 1",
"title#2": "label 2",
"title#3": "label 3",
"title#4": "label 4",
"title#5": "label 5",
"title#6": "label 6",
"title#7": "label 7",
"title#8": "label 8",
"title#9": "label 9"
},
"path": "enumWithTranslations",
"errors": []
}
}
But for the enum’s items, it looks like this:
{
"id": "default.enum 0",
"defaultMessage": "enum 0",
"ctx": undefined
}