Comments (10)
Good question. A few points:
- This is possible using
SimpleSchema.extendOptions
andmySimpleSchema.validator
. These are undocumented, but collection2 uses them to addunique
,autoValue
,denyInsert
, anddenyUpdate
(and the upcomingindex
option). Note thatvalidator
adds a custom validator to theSimpleSchema
instance rather than to all. This is necessary for one of the validations that collection2 does, but in general maybe there should be aSimpleSchema.addValidator
orSimpleSchema.addKeyValidator
that adds support to all SS instances. I think this is what you're asking for. - A related idea on my list is to add a
custom
option that takes a function or array of functions. The functions would return eithertrue
or an error type string (same as howmySimpleSchema.validator
works now, but user-definable per field).
You can keep this open as a reminder to make these changes.
from meteor-simple-schema.
Also the custom
option would replace valueIsAllowed
.
from meteor-simple-schema.
Thanks for letting me know! I'll have a closer look at the source code then.
from meteor-simple-schema.
I have hit on a requirement that in fact seems very related to this. Here's a discusson thread that's related, and below is a simplified example of what I'd like available:
BaseSchema = new SimpleSchema({
name: {
type: String,
min: 3
},
middleName: {
type: String,
optional: true
},
lastName: {
type: String,
min: 3
}
});
ExtendedSchema = new SimpleSchema([
BaseSchema,
{
name: {
min: 5,
max: 10
},
middleName: {
optional: false
},
age: {
type: Number,
min: 1,
max: 100
}
}
]);
As you can see, I'd like the ability to override or add to the properties of another schema that's included into this one.
from meteor-simple-schema.
Yep, we'd just need to _.extend the individual field definitions rather than the schema object as a whole. It's actually related to Meteor-Community-Packages/meteor-collection2#44.
from meteor-simple-schema.
Hmm, apart from the users collection enhancement, I don't see a specific reason to do this on collection2. I feel, keeping this on simple-schema on the other hand, would also empower those who don't use collection2.
Also contextually speaking, I believe rules about schema validation should reside in the schema object, rather than the collection object.
from meteor-simple-schema.
Agreed, it would be done on SS, but used by C2 for Meteor.users. I might do the development later today since it should be relatively easy.
from meteor-simple-schema.
$('<button/>', {text: 'Like :)'}).appendTo(this).click();
from meteor-simple-schema.
@serkandurusoy, you should now be able to merge/extend schema fields in the way you describe. @matteodem, take a look at Custom Validation. This should address your original issue (and more!).
from meteor-simple-schema.
Great, thanks. I'll dive right in.
from meteor-simple-schema.
Related Issues (20)
- AutoValue Doesn't Run On Server HOT 1
- [solved] custom function validation error HOT 1
- autoValue: calling fields() and siblingFields() yields no results on insert HOT 2
- Overwriting SimpleSchema regEx messages HOT 5
- Error: Invalid definition for inMenu field HOT 1
- Match.Where being instantiated as a class, causes error on Meteor 1.6.1 boot HOT 5
- Make a field conditionally required bug HOT 1
- Explicitly indicate this repo is deprecated HOT 1
- How to define a Custom Validation Error in Autoform >= 6.0 HOT 1
- Removing old field from old users? Ignore schema when using $unset ? HOT 1
- typo in dependencies in version 3.0.0 HOT 1
- 1.6.2 Has removed Deps from Tracker package HOT 4
- Warn / strip global regEx schemas? HOT 1
- the optional: true afFieldInput have the required attribute with it HOT 1
- error in Documentation [max] > {{max}} HOT 1
- "must be an object" error even though typeof() returns Object HOT 3
- $pull not behaving as expected HOT 1
- Move this package to Community Packages to support simpl-schema >=3.x HOT 1
- Update autoValue to accept async function HOT 2
- Typescript error when importing SimpleSchema 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 meteor-simple-schema.