esbanarango / ember-model-validator Goto Github PK
View Code? Open in Web Editor NEWember-cli addon adds validation support to your Ember-Data models.
Home Page: http://esbanarango.github.io/ember-model-validator/
License: MIT License
ember-cli addon adds validation support to your Ember-Data models.
Home Page: http://esbanarango.github.io/ember-model-validator/
License: MIT License
Model validator shouldn't be a mixin but part of the DS.Model object by default.
DEPRECATION: Enumerable#contains
is deprecated, use Enumerable#includes
instead. On ember#2.7.2
I have a property observing model-validator mixin property validationErrors but this is not observing the changes done in model values which are already validated. So it needs an explicit call to validate() method to update the error values in the form. Please guide us how to handle this here.
This looks like an awesome addon! β΅οΈ
I think many Ember users also know about ember-changeset-validations. Would you be willing to make a short comparison between the two, listing pros/cons. I think it would be very helpful to people trying to understand this addon.
I did not get ember-model-validator to work, I did the following in my model:
export default Model.extend(Validator,{
login: attr(),
password: attr(),
validations: {
login: {
presence: true
}
},
I get the warning when I am creating a new user:
WARNING: Interacting with a record errors object will no longer change the record state.
These values: '1', 1, and true should be the acceptable values. But the user can specify it as well with the accept
option.
Hi,
I can't get the model inside the router,
I am getting an error:
TypeError: fakeModel is undefined
or
TypeError: fakeModel.validate is not a function
also I am using ember-mirage as a single mock server.
Hi
Is there a way to add i18n support for the default error messages (like "can't be blank"). Especially if it would work with ember-i18n :) ?
3.15.1
to 3.15.2
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ember-cli is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
ui
is not present and a warning will be emitted. @tmquinnThank you to all who took the time to contribute!
The new version differs by 9 commits.
e17502b
3.15.2
4f1a5bb
Add v3.15.2 to CHANGELOG.md.
9e904a9
Avoid errors when ui
is not present and a warning will be emi⦠(#9014)
e164076
Supply a more universal .ui
972b3a0
Allow failure of Node 8 CI jobs. (#9015)
c89428a
Allow failure of Node 8 CI jobs.
dc95c25
fix named UMD imports (#8924)
bc6d511
allow importing named UMD files
98d3928
remove amd-shim duplication
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
1.5.2
to 1.5.3
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ember-template-lint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
no-action-modifiers
and no-element-event-actions
rules to suggest using the on
modifier (@bmish).template-lintrc.js
(@pgengler)The new version differs by 11 commits.
e75fa8e
Release 1.5.3
cf82a30
Merge pull request #805 from bmish/on-recommendation
8266a43
fix: update no-action-modifiers
and no-element-event-actions
rules to suggest using the on
modifier
978df8d
Add yarn lint
script which calls yarn lint:js
(#806)
8575c86
build(deps-dev): bump eslint-config-prettier from 6.0.0 to 6.1.0
9d86807
build(deps-dev): bump eslint from 6.1.0 to 6.2.0
169cc09
Add yarn lint
script which calls yarn lint:js
.
2e265db
build(deps): bump @glimmer/compiler from 0.41.4 to 0.42.0 (#802)
fd7275a
Add 'octane' config to export list so it can be found (#803)
3ff1cfb
Add 'octane' config to export list so it can be found (fixes #799)
440ea99
build(deps): bump @glimmer/compiler from 0.41.4 to 0.42.0
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
Is it possible to configure a date validation with something like this?
{
date: {
after: {
value: '2016-12-01',
message: 'should be before 2016-12-01'
},
before: {
value: '2016-12-12'
message: 'should be after 2016-12-12'
}
}
}
Hello! I've faced with a validation problem of an Email address: [email protected]
It will throw the validation error, but it is right Email address.
It should have the option to validate in different countries, or at least, Canada and US.
This is an example of a Canadian zipcode: T2A2V8
Hey!
I'm working with ember-model-validator and EmberData 2.1 and I'm having an issue validating a belongsTo relationship. I'm using version 1.1.0 of ember-model-validator
I've create my model like the following
import DS from 'ember-data';
import Ember from 'ember';
import Validator from 'weldnote/mixins/model-validator';
const { computed, isEmpty, inject } = Ember;
const { belongsTo } = DS;
export default DS.Model.extend(Validator, {
i18n: inject.service(),
code: belongsTo('industry-code', { async: false }),
validations: {
code: {
presence: true
}
}
});
When I call validate() the code
is considered to be empty (but it's not).
I've managed to debug the issue to the following:
//model-validator.js
_validatePresence: function _validatePresence(property, validation) {
var propertyValue = this.get(property);
// If the property is an async relationship.
if (this._modelRelations() && !Ember['default'].isBlank(this._modelRelations()[property])) {
propertyValue = this.get(property + '.content'); // Here is the problem
}
if (Ember['default'].isBlank(propertyValue)) {
this.set('isValidNow', false);
this._addToErrors(property, validation.presence, Messages['default'].presenceMessage);
}
},
If I console.log propertyValue
, right before the this.get(property + .content')
I get the following
Class {store: Class, container: Container, _internalModel: ember$data$lib$system$model$internal$model$$InternalModel, isError: false, adapterError: (...)
But the this.get(property + '.content') returns undefined.... was it this way with older versions of Ember Data (I'm guessing that's my problem).
I've been dealing with this through custom validations, but it's kind of annoying to always do this:
validations: {
code: {
custom: {
validation(key, value, model) {
let id = model.get('code.id');
return !isEmpty(id);
}, message(key, value) {
let translation = value.translate('edit-view.attributes.required');
return translation;
}
}
}
Thanks a lot for the project. It's been very helpful
3.1.2
to 3.1.4
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ember-ajax is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 3 commits.
430d11c
chore(release): 3.1.4
ba9a87d
test: add test case around relative URL conversion
daf8319
Revert "fix: don't append leading '/' when building url"
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
3.0.0
to 3.0.1
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ember-cli-htmlbars-inline-precompile is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 22 commits.
0a33678
Release 3.0.1
2517d5d
Merge pull request #320 from rwjblue/deprecate-and-noop
d3a4f4a
Deprecate ember-cli-htmlbars-inline-precompiler.
a6f25ed
Re-roll yarn.lock (#321)
0eced26
Re-roll yarn.lock
ae928fe
Bump ember-cli-babel from 7.11.0 to 7.11.1
3b758a0
Bump ember-resolver from 5.2.1 to 5.3.0
c28a548
Fix import in README example (#305)
fc2d80b
Fix import in README example
3937089
Bump release-it from 12.4.0 to 12.4.1
1307f86
Bump release-it from 12.3.6 to 12.4.0
36d663e
Bump eslint from 6.3.0 to 6.4.0
f897fb0
Bump babel-plugin-htmlbars-inline-precompile from 2.0.0 to 2.1.0
a66feba
Merge pull request #299 from ember-cli/rwjblue-patch-1
93f776b
Remove problematic Chrome flags
There are 22 commits in total.
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
I have the following model
import DS from 'ember-data';
import Validator from '../mixins/model-validator';
var attr = DS.attr;
export default DS.Model.extend(Validator, {
plan: DS.belongsTo('plan', {async: true}),
validations: {
plan: {
presence: {
message: 'Please select a plan'
}
}
}
});
Then when I'm trying to validate a model trying to test the behavior when the validation fail, the validation pass, but if I delete the {async: true}
the validations doesn't pass (as expected)
HI,
I noticed that if I have:
logoUrl: {
URL:true,
},
It required from me value cuz empty string or null
is always invalid. Is there an option for make any empty string or null always valid?
Hey,
I stumbled upon an issue with custom messages not receiving the values correctly. I've create this PR to fix the issue. Hope it helps :)
Thanks for the great addon.
in https://github.com/esbanarango/ember-model-validator/blob/master/addon/mixins/model-validator.js#L38
you are making a transition to the state updated.uncommitted
and that set model properties to isNew == false
and isDirty == true
breaking the API like this: https://gist.github.com/sescobb27/5becc19ba451a18f5e15
a workaround to fix that problem is this, but it isn't generic for all situations.
if (!order.get('id')) {
if (order.get('currentState.stateName') === 'root.loaded.updated.uncommitted') {
order.transitionTo('loaded.created.uncommitted');
}
return order.save().then(deferred.resolve);
}
I think you should save the previous state of the model, and when the model is valid again reset that state
I have set out to give ember-model-validator
a serious try-out. It would be very helpful for me, if the documentation included an example (best practice) about how to use the error-list in a template.
For instance, look at the example at http://esbanarango.github.io/ember-model-validator/#/validators/length.
Here, it is possible to trigger several errors at the same time - great!
How do you relate errors for a specific model attribute to the field displaying this attribute? Are you using computed properties**?**
How do you make the error-messages immediately disappear from display and error-list, when starting to type something into a specific error-prone field, while all other errors keeps existing in the error-list and keeps being displayed**?**
7.13.0
to 7.13.1
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ember-cli-babel is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.
The new version differs by 5 commits.
a72f8b0
Release 7.13.1
0d4dcc3
Include decorator and class field plugins after TypeScript, if p⦠(#311)
e08b59d
Include decorator and class field plugins after TypeScript, if present
bc0dee4
README: Update an outdated link (#309)
3f6e108
README: Update an outdated link
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
numericality: {
onlyInteger: true,
allowBlank: true
}
Is there a reason why Ember.isBlank() is being used instead of Ember.isEmpty()?
For the above validation, x = ' ' validates as true, which is expected using isBlank. Coupled with an onlyInteger validation, this doesn't quite make sense.
1.14.2
to 1.14.3
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
sass is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
To install Dart Sass 1.14.3, download one of the packages above and add it to your PATH, or see the Sass website for full installation instructions.
Treat :before
, :after
, :first-line
, and :first-letter
as pseudo-elements for the purposes of @extend
.
When running in compressed mode, remove spaces around combinators in complex selectors, so a selector like a > b
is output as a>b
.
Properly indicate the source span for errors involving binary operation expressions whose operands are parenthesized.
See the full changelog for changes in earlier releases.
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
Hi there,
I just upgraded ember-data, ember-cli and ember-source to 2.15 and I got this message from my model validator. Could you plz help me to find a solution on this issue?
Hello there!
First, let me thank you for this very good addon!
Concerning error messages for the length constraint, is there a way to have different messages for minimum and maximum?
Something like this would be great:
length: {
minimum: {
value: 3,
message: 'form.errors.tooShort'
}
}
I need to validate a field only if another attribute has an specific value and I don't know if the library has this option.
i.e. something like this:
validations: {
images: {
presence: true,
validateIf: function () { return 'gallery' === this.get('type'); }
}
}
I know I can do it with customValidators so I can solve it that way right but it feels better this way because I can reuse the base validations of the library. Does this exists? If not, I can check the code and add it with a PR.
Validations for related models are not run when the relationship is defined like DS.hasMany('related-model', {async: false})
I believe this is a regression introduced in this commit. I think in this case the related objects are not wrapped in a proxy so the content
property is undefined.
I am currently using ember-data 2.8.1
Hi,
I have a model 'property' and 'flat'.
Flat inherits from property, but when i declare validations in both, only 'Flat' validators show, because they are rewritten.
How can I use validations from the parent in the child class?
I see that there is the relation: ['belongsTo']
but I want to only check for the relation if a different relationship's property is true
Using Ember 2.0.0 with Ember Data 2.1.0 and ember-model-validator I get a warning when validating numericality.
numericality: {
allowBlank: true,
greaterThanOrEqualTo: 0,
lessThanOrEqualTo: 30
}
DEPRECATION: Ember.String.fmt is deprecated, use ES6 template strings instead. [deprecation id: ember-string-utils.fmt] See https://babeljs.io/docs/learn-es6/#template-strings for more details.
at Object.fmt (http://localhost:4200/assets/vendor.js:44511:29)
at _validateNumericality (http://localhost:4200/assets/vendor.js:167958:88)
In these lines is where the situation occurs.
This validator should accept the same options as the Active Record Numericality validator.
1.8.2
to 1.10.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ember-cli-inject-live-reload is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 9 commits.
60b2ba2
1.10.0
415935b
Add yarn.lock.
542a2a0
Migrate to lerna-changelog + add 1.10.0 to changelog.
a21fd1d
Merge pull request #55 from SparshithNR/path-fix
f6d8238
Provide backward compatibility.
ab29353
Pass path as argument to livereload.js
68c237e
release v1.9.0 π
2e88996
Merge pull request #54 from SparshithNR/test-refactor
fcd41eb
Refactoring and Tests
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
This way we can be specific about which validations run.
6.9.1
to 6.10.0
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
eslint-plugin-ember is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
allowDynamicKeys
option (default true) to require-computed-property-dependencies
rule (@bmish)The new version differs by 7 commits.
590cf98
v6.10.0
46502cf
Update CHANGELOG
2e0469e
Merge pull request #473 from raycohen/no-inline-anonymous-functions-to-schedule-once
434b44d
Merge pull request #476 from bmish/require-computed-property-dependencies-allowDynamicKeys-option
5a9a0fe
Add new no-incorrect-calls-with-inline-anonymous-functions
rule
55537f6
build(deps): bump ember-rfc176-data from 0.3.10 to 0.3.11 (#478)
2733279
fix: add allowDynamicKeys
option (default true) to require-computed-property-dependencies
rule
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
in store.recordWasInvalid(this, errors);
throws an error Uncaught TypeError: internalModel.adapterDidInvalidate is not a function
.
reading the source code of ember-data I found this
// ===== InternalModel
// FOR USE DURING COMMIT PROCESS
/**
@method adapterDidInvalidate
@private
*/
adapterDidInvalidate: function (errors) {
var recordErrors = this.getErrors();
ember$data$lib$system$model$internal$model$$forEach.call(Ember.keys(errors), function (key) {
recordErrors.add(key, errors[key]);
});
this._saveWasRejected();
}
// ===== InternalModel
/**
This method is called once the promise returned by an
adapter's `createRecord`, `updateRecord` or `deleteRecord`
is rejected with a `DS.InvalidError`.
@method recordWasInvalid
@private
@param {InternalModel} internalModel
@param {Object} errors
*/
recordWasInvalid: function (internalModel, errors) {
internalModel.adapterDidInvalidate(errors);
}
I think you should not call that method manually, instead make something like this: https://github.com/dockyard/ember-validations/blob/master/addon/validators/local/inclusion.js#L23
First, thanks for your library it help me a lot.
Second, is there a way to prioritize errors message. For example, i have a too short message and a required message to show.
I would like to show "Requiredt" when its empty, not both. And if it too short, only "Too short".
Thanks man !
3.0.0
to 3.0.1
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
ember-cli-htmlbars is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 4 commits.
48a5b69
release v3.0.1 π
fcf265a
fix memory leak (adapted from @arthirmβs ember-cli/ember-cli-htmlbars-inline-precompile#112)
28d825f
Merge pull request #124 from ember-cli/upgrades
c54e610
Bump deps
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
If I put a numericality validator on one of my nullable number fields, validation will fail if input is blank. The validator should not assume the behavior of the presence validator; presence should be specified separately.
There are a bunch of pre-existing code that uses the locale
property of the model:
// my-model
export default Model.extend(Validator, {
locale: attr('string'),
...
})
This conflicts with the locale property defined here: https://github.com/esbanarango/ember-model-validator/blob/master/addon/mixins/model-validator.js#L31-L38
There are obvious workarounds:
Validator
myLocale: attr('string', { key: 'locale' })
and update all existing codeIn general, Ember addons tend to be very aggressive with claiming keys in users' namespaces (see emberjs/data#973), so this code is idiomatic.
But what's the suggested workaround?
Also posting so that anyone else with the problem can find it (and a solution, if there is one).
cc @rwwagner90 @jblakeman
To reproduce:
on super class:
on sub class:
test:
In the model I did like this:
import Ember from 'ember';
import Validator from 'ember-model-validator/mixins/model-validator';
export default Model.extend(Validator,{
login: attr(),
password: attr(),
validations: {
login: {
presence: true
},
password: {
presence: true
}
},
});
In the template.hbs I do something like this:
<table>
<tbody>
<tr>
<td>{{input value=login}}</td>
<td>{{input value=password}}</td>
</tr>
</tbody>
</table>
It does not show anything when I try to submit empty login or password.
Do I need to do something else ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.