-
-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validators for jsonfield are not updated with dynamic schema #161
Comments
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:
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 Breaking change: Yes. Changing the |
@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. |
Hi, thanks a lot for reply. I will try soon and write about updates, ser |
I want to update schema depending on separate field of model (e.g. "kind"). So there is a two main logic how to upload schema dynamically:
I have used callable schema and used js API for dynamic schema updating.
There is one issue related to validation, to be precise, jsonfield saves validation rules of schema which was loaded while
python manage.py runserver
. E.g.The text was updated successfully, but these errors were encountered: