Comments (4)
@AntonyDeveau and I came across a solution for simple cases of inheritance. It goes no further than exporting and merging validation properties, but it's a start.
Here's an example:
parent.js
export let validations = {
aFieldInTheParent: {
presence: {message: 'This field must be there'}
};
export default Resource.extend({
aFieldInTheParent: DS.attr('string'),
validations: validations
});
child.js
import Parent from './parent';
import { parentValidations } from './parent';
export default Parent.extend({
aFieldInTheChild: DS.attr('number'),
validations: Ember.merge(parentValidations, {
aFieldInTheChild: {
numericality: {
greaterThan: 0,
message: 'This must be greater than 0.'
}
}
})
});
Note that we haven't tested whether added validations on then parent's fields in the child work. This depends on how Ember.merge works, although this can be overriden by your own merging logic.
Hope that may help someone (@NullVoxPopuli)
from ember-model-validator.
Turns out merging as I wrote it actually changed the parent's validations and put the child's instead.
Validations should actually be copied first, like so:
child.js
import Parent from './parent';
import { parentValidations } from './parent';
export default Parent.extend({
aFieldInTheChild: DS.attr('number'),
validations: Ember.merge(Ember.copy(parentValidations, true), {
aFieldInTheChild: {
numericality: {
greaterThan: 0,
message: 'This must be greater than 0.'
}
}
})
});
from ember-model-validator.
from ember-model-validator.
thanks for the merging idea!
from ember-model-validator.
Related Issues (20)
- An in-range update of ember-cli-htmlbars is breaking the build 🚨 HOT 1
- An in-range update of ember-cli-inject-live-reload is breaking the build 🚨 HOT 2
- An in-range update of sass is breaking the build 🚨 HOT 10
- An in-range update of ember-ajax is breaking the build 🚨 HOT 1
- An in-range update of eslint-plugin-ember is breaking the build 🚨 HOT 2
- An in-range update of ember-template-lint is breaking the build 🚨 HOT 12
- An in-range update of ember-cli-htmlbars-inline-precompile is breaking the build 🚨 HOT 1
- An in-range update of ember-cli-babel is breaking the build 🚨 HOT 9
- An in-range update of ember-cli is breaking the build 🚨 HOT 2
- An in-range update of ember-cli-htmlbars is breaking the build 🚨 HOT 1
- When do you plan to make next release? HOT 2
- `errors` is a proxy object with no length HOT 2
- model.validate() causes error HOT 6
- ember-global deprecation warning on 3.28 HOT 2
- Potential Feature: Validate from template function HOT 1
- InternalModel removed in ember 4.6 HOT 1
- not validate octane relations HOT 1
- Error with [email protected] and ember 4.6+ HOT 1
- Error with ember model fragment while validating with ember-model-validator
- Add support to validate nested objects
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 ember-model-validator.