Comments (9)
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.
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.
@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.
yep, json schema.
from daybed.
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.
Json Schema good parts:
- Automatic form generation: https://github.com/exavolt/onde
Demo: http://exavolt.github.io/onde/#?schema_url=schemas/jquery-package.json - Form generation again: https://github.com/joshfire/jsonform
- Schema editor: http://www.jsonschema.net/
- Backbonejs integration https://github.com/redpie/backbone-schema
from daybed.
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.
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.
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)
- Plug loads with Daybed functional tests
- Resolve relation fields
- Add definition PUT, that would create/update models HOT 4
- Plugin idea : Daybed history HOT 2
- Hide the system.Everyone and system.Authenticated pyramid paradigm from daybed users.
- Record validation error appears several times in response
- Sharing single records HOT 7
- GET model definition should return the required parameter for all fields. HOT 6
- Multiple time the same validation errors HOT 2
- Missing location header in PUT /models/:id
- PUT/POST /models/:modelid/records with an unknown field type in the model definition (stored in the database) raise a 500 HOT 4
- Mention appback among competitors
- Should store deserialized value of records HOT 1
- Revoke / update tokens
- Redis backend: colander.null is not JSON serializable
- ElasticSearch bottleneck for batch record creation HOT 1
- [CouchDB] Having a - in the model name breaks the server
- Include the list of plugins in the hello page.
- Document the Daybed search endpoint
- Let's define a model field as primaryKey that will be used on the POST /records and validated with the recordId on PUT HOT 6
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 daybed.