Comments (6)
That should be easy to achieve just by adding a custom validator (on your model schema). Note that contextable.js is using objectschema.js and validatable.js under the hood thus you will find details there.
Here is just a hint on how your schema should look like (check the docs for details):
export const schema = new Schema({
fields: {
name: {
type: 'String',
validate: [
{
validator: 'myCustomValidator',
message: 'is required'
}
]
}
},
validatorOptions: { // this is passed directly to validatable.js Validator class
validators: {
async myCustomValidator ({value, recipe}}) { // function or promise
return this.field1 && this.field2 && this.somethingElse; // return true when valid
}
}
}
});
Note also that a validator's context is Model
so you can access model's fields by using this.{field}
. If you have nested structure, then you access parent model as this.$parent
. Let me know if that helps.
from vue-rawmodel.
Maybe we could add the if
or only
key which would run field validation only if listed validators are true. If you think this is a good idea, you can open a new issue here.
from vue-rawmodel.
Feature requested here rawmodel/framework#2.
from vue-rawmodel.
Thanks - the example of the custom validator was sufficient for my needs although it would be simpler if there was an if key for the presence validator (not so sure about the use cases more generally).
from vue-rawmodel.
@michaelsorich cool. The feature you requested will be added in one of the future releases.
from vue-rawmodel.
The latest contextable.js now provides the condition
option.
from vue-rawmodel.
Related Issues (13)
- Example on loading data into model HOT 4
- How to set up a date field properly? HOT 4
- Shared client and server side validation models HOT 7
- Nested models and reactivity
- Update for current rawmodel? HOT 3
- Clarification of how to use nested schemas/models HOT 5
- Saving only changed and valid fields HOT 4
- Docs for use with server rendering HOT 2
- Using Vuex HOT 1
- new API and renaming from vue-contextable to vue-rawmodel
- Decorator support HOT 2
- Any way to check if the field is dirty? HOT 2
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 vue-rawmodel.