-
Notifications
You must be signed in to change notification settings - Fork 16
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
Proposal: Add validations to the data array #12
Comments
In speaking with some coworkers, they feel there might not be a need for Similarly, he suggested using I would prefer that a validator be tied to a specific type, but I thought I would mention the other side here. |
I see a problem with it, but it'd be @mamund 's decision to accept it or not. In CJ values are supposed to be strings, only. So this wouldn't be spec compliant: "value": ["red", "green", "blue"] However, it's somehow also a problem to write it as a string, because it could lead to some weird scenarios where comma separated values are not really to be treated as arrays. Maybe a "values": ["red", "green", "blue"] |
yep -- one of the challenges for this design will be dealing with the as Carles points out, the "value" keyword is already defined as a string mamund On Thu, Feb 19, 2015 at 2:16 AM, Carles Jove i Buxeda <
|
That makes sense, thanks for bringing that up. (also thinking out loud) I think that {
"collection": {
"version": "1.0",
"href": "http://www.example.com/file_upload",
"template":{
"data": [{
"name": "file",
"value": null,
"validations": [{
"name": "file_size",
"prompt": "The maximum size for a file",
"arguments": [{
"name": "lower_bound",
"value": "0"
},{
"name": "upper_bound",
"value": "2097152"
}]
}, {
"name": "file_type",
"prompt": "allowed file types",
"arguments": [{
"name": "option",
"value": "png"
},{
"name": "option",
"value": "bmp"
},{
"name": "option",
"value": "jpg"
},{
"name": "option",
"value": "gif"
}]
}]
},{
"name": "label",
"value": null,
"validations": [{
"name": "length",
"prompt": "The allowed length of the label",
"arguments": [{
"name": "lower_bound",
"value": "0"
},{
"name": "upper_bound",
"value": "50"
}]
}]
},{
"name": "background_color",
"value": null,
"validations": [{
"name": "inclusion",
"prompt": "The list of allowed background colors",
"arguments": [{
"name": "option",
"value": "red"
},{
"name": "option",
"value": "green"
},{
"name": "option",
"value": "blue"
}]
}]
},{
"name": "email_address",
"value": null,
"validations": [{
"name": "format",
"prompt": "regex pattern for an email address",
"arguments": [{
"name": "regex",
"value": "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b"
}]
}]
}]
}
}
} |
Following on this (the problem with
|
Reference: https://groups.google.com/forum/?fromgroups=#!topic/collectionjson/Q2dnK82ok9A
Use Case: We would like to add the ability to pass validation information along to our front end clients to compliment our server-side validations. This is to help reduce potentially expensive operations on the server. Our particular scenario is to try to catch invalid file uploads before they are uploaded, but we see opportunities to use this to enrich our UX by having more responsive validations and reduce the risk of a divergence of logic between the two.
The proposed format for the validators is:
When proposing on the google group, the suggestion was raised that we would need a common set of validators. I reviewed a few validation libraries and below seemed to be a fairly common set, though the naming will look familiar to many a ruby and rails developer.
inclusion
- validates value to ensure it is within an Array of allowed values.exclusion
- validates value to ensure it is not within an Array of allowed values.format
- validates String to ensure it matches regexlength
- validates a String against and Array containing an upper and lower bound lengthfile_type
- validates a File against an Array of allowed file typesfile_size
- validates a File against an Array containing an upper and lower bound file sizepresence
- validates a value to ensure that it present (not null and not empty)If there are validators that are missing or the implementation is lacking for some specific needs please let me know. I will be working on a PR to link to this so we can have more of a work in progress.
The text was updated successfully, but these errors were encountered: