Comments (5)
Thanks for the issue.
You can of course define a custom rule that would do this for your purpose, let's work together to find the best way to implement this for your use-case.
I am resting until the 10th, I'll be in touch again afterwards.
FYI:
Related: when defining an array of objects, is there a way to define the type of the items inside the arrays? I.e: type=array + items="Object", or in the above example type=array + items=[Person,Organization] might make sense for instance
Should be resolved with:
You should be able to find a test case for this - let me know if there isn't one!
from async-validate.
Here is my current thinking, we define a rule property such as resolve
which points to a function that inspects the object being processed and returns the rule to execute for that object. The function would be called synchronously and must return a valid rule, for example:
var Person = // define rule for person
var MusicGroup = // define rule for music group
function resolve() {
switch(this['@type']) { // called with `this` as the object being validated
case "Person":
return Person;
case "MusicGroup":
return MusicGroup;
}
throw new Error('Unknown @type encountered')
}
Then in the rule declaration assign the resolve()
function to the resolve
property which would be executed to locate the rule.
How does that sound?
from async-validate.
Yep sounds good to me.
FYI: moved on by doing some custom hacking in schema.js
that let's me
circumvent the issue since I needed some other stuff as well, but this
certainly seems to solve this particular issue pretty elegantly.
On Fri, Jan 8, 2016 at 12:00 PM, muji [email protected] wrote:
Here is my current thinking, we define a rule property such as resolve
which points to a function that inspects the object being processed and
returns the rule to execute for that object. The function would be called
synchronously and must return a valid rule, for example:var Person = // define rule for personvar MusicGroup = // define rule for music groupfunction resolve() {
switch(this['@type']) { // called withthis
as the object being validated
case "Person":
return Person;
case "MusicGroup":
return MusicGroup;
}
throw new Error('Unknown @type encountered')
}Then in the rule declaration assign the resolve() function to the resolve
property which would be executed to locate the rule.How does that sound?
—
Reply to this email directly or view it on GitHub
#56 (comment)
.
from async-validate.
This has been implemented in ef53cae.
Added to the readme here:
https://github.com/tmpfs/async-validate#resolve
Test spec is here:
https://github.com/tmpfs/async-validate/blob/master/test/spec/resolve.js
Published to the registry as 0.12.4
.
I have found a bug noted here #57 which may or may not be related to the resolve
implementation, I have a feeling this is a wider issue to do with handling arrays at the top-level, will investigate later.
For the moment I am closing this particular issue as implemented - hope it helps!
from async-validate.
cheers!
On Tue, Jan 12, 2016 at 7:02 AM, muji [email protected] wrote:
—
Reply to this email directly or view it on GitHub
#56 (comment).
from async-validate.
Related Issues (20)
- Rename method type identifier to function
- Implement match property HOT 1
- Implement system schema HOT 1
- Make fields property required (remove shorthand)
- Document match property HOT 1
- Document local property HOT 1
- Document format property HOT 1
- Create command line interface
- ANN: Discuss v1 release HOT 2
- Support top-level array with resolve HOT 1
- empty string should be raised when rules include `required` HOT 1
- Remove field name in custom error messages HOT 21
- Override global default error messages HOT 2
- How to validate against other values? HOT 6
- pattern.schema.email only allows TLDs of 6 characters HOT 1
- Wrong behavior with deep rules HOT 5
- after invoke some times, the `type: ['string', 'object']` --> `type: ['string']. HOT 5
- about form data validator ,data type is number or date ,from data validator not through. HOT 1
- 非常严重的问题
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 async-validate.