bhch / django-jsonform

A better, user-friendly JSON editing form field for Django admin. Also supports Postgres ArrayField.
https://django-jsonform.rtfd.io
BSD 3-Clause "New" or "Revised" License
307 stars 31 forks source link

Weird validation in Django Admin when using array + choice + multiselect #171

Open AlTosterino opened 2 weeks ago

AlTosterino commented 2 weeks ago

Hey!

I encountered a strange validation behavior when using the below schema:

{
    "type": "object",
    "keys": {
        "source_ids": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
                "type": "string",
                "widget": "multiselect",
                "title": "Source fields",
                "choices": [
                    {"title": "Test", "value": "b7f368af-a173-4079-8348-e1b9625f220f"},
                    {"title": "Test 2", "value": "277d180c-7be0-495a-8685-340e08734599"},
                ],
            },
        }
    },
}

When trying to save the form, validation correctly shows: Minimum 1 items required. But it's setting up the initial values of the dropdowns to empty string, see below:

Zrzut ekranu 2024-06-21 o 14 33 45

When saving the form again, validation correctly shows: Invalid choice

image

Using widget.validate_on_submit=True helps with the first problem (setting initial values for dropdowns) but it does not behave correctly with the choices, see below

image

Expected behavior: