how to set required fields ?
AdrienLemaire opened this issue · 3 comments
It looks like json-editor allows setting a required
option to define what fields should be required or not.
I tried a schema like this:
HOST_ROLES_SCHEMA = {
'type': 'array',
'title': 'roles',
'format': 'table',
'items': {
'type': 'object',
'required': [
'name',
'tag',
],
'properties': {
'name': {
'title': 'Name',
'type': 'string',
'format': 'text',
},
'tag': {
'title': 'Tag',
'type': 'string',
'format': 'text',
}
}
}
}
I also tried this version:
I tried a schema like this:
HOST_ROLES_SCHEMA = {
'type': 'array',
'title': 'roles',
'format': 'table',
'items': {
'type': 'object',
'properties': {
'name': {
'title': 'Name',
'type': 'string',
'format': 'text',
'required': True,
},
'tag': {
'title': 'Tag',
'type': 'string',
'format': 'text',
'required': True,
}
}
}
}
But I can keep saving the model with empty fields in django admin. Is this property not supported ? Do I need to add some custom code to handle it myself ? Not seeing any required html attribute or class name in the generated html output, I'm not sure where to go from there.
@Fandekasp I have added an example with required fields.
The required allows you to specify the keys that must be presented in the object and values can be empty. If you want a non-empty value you should use minLength property.
Sorry for the late reply. Thanks !