Giter Site home page Giter Site logo

Comments (9)

AntoineCezar avatar AntoineCezar commented on August 18, 2024

And I prefer this to be agnostic even if it will not solve all the cases.

Exemple 1:

fields: [
    {
        type: "int",
        name: "age",
        description: "Your mother age",
        max: 120,
        min: 15
    },

Exemple 2:

fields: [
    {
        type: "int",
        name: "age",
        description: "Your mother age",
        in: [2, 3, 5],
    },

If age is not valid it returns a 400 type response:

errors: [
    {
        field: "age",
        message: "..."
    }
]

from daybed.

almet avatar almet commented on August 18, 2024

I'm wondering if we shouldn't just use Javascript schema here, I've heard that it's not too complicated to parse; I don't know if that's the same story for its generation

from daybed.

leplatrem avatar leplatrem commented on August 18, 2024

@AntoineCezar The two examples you gave are already covered by either RangeField or EnumField.

With validation functions I had something more elaborate, even something like cross fields validation !

@ametaireau Do you mean JSON schema ?

from daybed.

almet avatar almet commented on August 18, 2024

yep, json schema.

from daybed.

leplatrem avatar leplatrem commented on August 18, 2024
   validation: "return (fields.single || fields.wedding_date > 1900)"

Parsed and executed in python, or JS executed server-side with http://code.google.com/p/pyv8/

from daybed.

AntoineCezar avatar AntoineCezar commented on August 18, 2024

Json Schema good parts:

from daybed.

leplatrem avatar leplatrem commented on August 18, 2024

Seems interesting indeed, but it looks like a different story : "replacing current formalism for model definitions by JSON schema".
This one was dedicated to "custom validation logic between fields". Should I rename it and create an another one?

BTW, transforming current JSON to Backbone forms is currently done like this:
https://github.com/leplatrem/daybed-map/blob/master/backbone-daybed.js#L151-L204

Nothing extra is required for models. Except we want to have stuff like derived types (colour stored in string field) :
https://github.com/leplatrem/daybed-map/blob/master/app.js#L23-L31

from daybed.

AntoineCezar avatar AntoineCezar commented on August 18, 2024

The title is "Validation function at model field definition" not "custom validation logic between fields". So It contains the problem and the solution. Renaming may be necessary.

I'd like to avoid a language specific solution, but if there no other way let's do it in JavaScript.

from daybed.

leplatrem avatar leplatrem commented on August 18, 2024

Completely agree with what's being said here.

Regarding the original issue, adding custom validation between fields at model definition level is probably a bad idea. @AntoineCezar pointed this out with the "password confirmation" example (two fields in form, validated together, but not relevant in the model itself).

BTW Chris Mcdonough said decoupling models from forms was a good idea :) http://pyvideo.org/video/1407/about-django-from-the-pyramid-guy

This custom validation between fields may then be left to client-side.

from daybed.

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.