Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

select inputType and integer type #115

Open
js-ta opened this issue Jan 23, 2025 · 2 comments
Open

select inputType and integer type #115

js-ta opened this issue Jan 23, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@js-ta
Copy link

js-ta commented Jan 23, 2025

Hello,

in #50 I saw a similar problem to the one I have.
If I try to use the same schema, but with "type": "integer" instead of "type":"number", I get the error following error:

Error: yupSchema.integer is not a function

This is reproducable in your playground.

Here is the schema:

{
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "AccountType": {
            "title": "Select account type",
            "description": "",
            "x-jsf-presentation": {
                "inputType": "select"
            },
            "oneOf": [
                {
                    "title": "Normal User",
                    "const": 0
                },
                {
                    "title": "Business",
                    "const": 1
                },
                {
                    "title": "Services Provider",
                    "const": 2
                }
            ],
            "type": "integer"
        }
    },
    "required": [],
    "x-jsf-order": [
        "AccountType"
    ]
}
@js-ta
Copy link
Author

js-ta commented Jan 23, 2025

Tried to quickly find what causes the problem:

generateOptionSchema does not handle an integer type. It is handled as string by default. Also withInteger is added to the validators which finally leads to the error.

When I extend generateOptionSchema by adding

case 'integer':
    return yupSchemas.radioOrSelectNumber(optionValues);

and prevent validators.push(withInteger) from being called when the field is a select by adding

const hasOptions = field.options?.length > 0;
if (jsonType === 'integer' && !hasOptions) {
    validators.push(withInteger);
}

I was able to workaround this issue.

@sandrina-p
Copy link
Collaborator

Hi @js-ta 👋 Thank you a lot for the report and digging into the root cause. Could you open a PR with the fix and a unit test? 🙇

@sandrina-p sandrina-p added the bug Something isn't working label Jan 24, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants