Git Product home page Git Product logo

Comments (3)

bhch avatar bhch commented on September 20, 2024

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:

  1. 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.
  2. 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.

bhch avatar bhch commented on September 20, 2024

@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.

ReadMost avatar ReadMost commented on September 20, 2024

Hi, thanks a lot for reply. I will try soon and write about updates, ser

from django-jsonform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.