Comments (3)
Notes to self:
Issue: Schema changed on client-side via JS breaks validation on server-side because the server validator uses the older schema available on the server.
Possible solutions:
- Submit the modified schema along with the form data. But that would be a security concern as the user can basically provide any kind of schema they wish. So, we can't do this.
- Let the developer deal with this by writing their own custom validator. Seems to be the most reasonable option.
Bug: Developer's custom validator will not run because, currently, the default form field validation is always run. This will raise a validation error because it uses the older schema for validation. That means the developer's custom validator will not run.
Fix: There needs to be a way to disable the default validation. Maybe move the validate()
method's logic into a validator and add it as default_validators = [...]
on the field. That way the developer can disable it and also set their custom validators.
Breaking change: Yes. Changing the validate()
method will break things if someone is overriding this method in their projects.
from django-jsonform.
@ReadMost Hi, thank you for reporting this issue. This will take some time to fix (please see my previous comment).
Meanwhile, you can handle the validation using your custom validator and disable the default validation. For that, you'll need to override the form field:
from django_jsonform.forms.fields import JSONFormField
# Create a subclass of the form field
class MyJSONFormField(JSONFormField):
def validate(self):
# run grand-parent's validate method
# skip parent's validate method
# https://stackoverflow.com/a/43016980/1925257
super(JSONFormField, self).validate()
# Now use your custom field in the form class
class MyModelForm(forms.ModelForm):
field = MyJSONFormField(validators=[my_custom_validator])
# Now use this custom form on the admin site
class MyModelAdmin(admin.ModelAdmin):
form = MyModelForm
Hopefully, this will help you until it gets fixed.
from django-jsonform.
Hi, thanks a lot for reply. I will try soon and write about updates, ser
from django-jsonform.
Related Issues (20)
- Setting JSONField schema dynamically HOT 3
- Copy-pasting / Duplications for Array items and Objects
- Horizontal display of properties HOT 1
- Dynamic header generation for array items HOT 2
- Customising "Add key" and "Add item" texts HOT 1
- Add button to open link in URLField HOT 5
- Decimal values not allowed when entering integer minimum and maximum for 'number' types HOT 4
- Define defaults for an array HOT 3
- Subfields in ArrayField should get the relevant input type
- Issue with errors for fields inside an anyOf schema not displaying correctly HOT 4
- Cooperation with other repository `django-pydantic-field` for model schema validation HOT 2
- Title is not populated for `oneOf` when referenced through `$ref` HOT 4
- tests dir in .venv broke project tests HOT 2
- JSONFieldWidget attrs HOT 1
- Bug: Nullable Subschema (anyOf with `null`) causes UI exception
- Type annotations / stubs HOT 1
- Weird validation in Django Admin when using array + choice + multiselect
- List of JSON data is not populating as expected HOT 5
- Meta-Schema: JSON validation with JSON Schema draft definition
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-jsonform.