Closed captain828 closed 10 months ago
Doing this inside a model's clean
method isn't possible because then the validation will be handled by the model (not the json field). So the model doesn't pass the error_map
object over to the json field.
What we want to do is to make this validation at the field level. So that field can catch the exception early and use the error_map
.
So, you are required to create a custom form for this and set a custom validator on the json field. See docs: https://django-jsonform.readthedocs.io/en/latest/guide/validation.html#creating-a-form
Awesome, thanks for clarifying!
Schema:
Custom validation inside model:
Tests:
submitting the form with no values - PASS
submitting the form with data that would fail the validation - FAIL
Expected result:
Versions:
The only thing I can think of is that
coords=[key]
isn't correct but the docs don't cover this simple case (they focus on an array with an object inside) and all the other ways I've tried didn't work.