Angular schema form default not picking up

2.4k Views Asked by At

we are using angular-schema-from for redring form from json schema and json from

Some how we are not getting default value for enum,

Please refer below form and schema...

Schema json:

{
    "type": "object",
    "title": "Comment",
    "properties": {
        "contactDetails": {
            "title": "Contact Person",
            "type": "array",
            "minItems": 1,
            "items": {
                "type": "object",
                "properties": {
                    "contactType": {
                        "title": "Contact Type",
                        "description": "Select",
                        "type": "string",
                        "default": "test",
                        "enum": ["test", "test1"]
                    }
                }
            }
        }
    }
}

Form json:

[
    "contactDetails[].contactType",
    {
        "type": "submit",
        "style": "btn-info",
        "title": "OK"
    }
]
1

There are 1 best solutions below

0
On

It's because of the array in combo with your form definition, you can't access a field inside an array without wrapping it in a a array type.

Try this form definition instead:

[
    {
        "type": "array",
        "key": "contactDetails",
        "items": [
            "contactDetails[].contactType"
        ]
    },
    {
        "type": "submit",
        "style": "btn-info",
        "title": "OK"
    }
]

Example: http://schemaform.io/examples/bootstrap-example.html#/c0cf38b387b84e567176