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
352 stars 34 forks source link

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

Closed AlTosterino closed 4 months ago

AlTosterino commented 5 months 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:

bhch commented 2 months ago

Released in v2.23.0.