anandts88 / ember-validator Goto Github PK
View Code? Open in Web Editor NEWPerform Ember Object Validation
License: MIT License
Perform Ember Object Validation
License: MIT License
It would be helpful if the object being validated was not restricted to an Ember Object
this.validateMap({ model: myPOJO, validations })
If a consuming application using this addon updates to Ember >=2.3.0
, deprecation messages will be triggered when the following line is hit. https://github.com/anandts88/ember-validator/blob/master/addon/mixin.js#L217
See new getOwner(this)
API for this specific case http://emberjs.com/deprecations/v2.x/#toc_deprecations-added-in-2-3
Specifically the https://github.com/rwjblue/ember-getowner-polyfill to support a wide array of Ember versions.
I'm trying to use the pattern
validator to validate a password. My code looks like this:
pattern: {
hasNumber: true,
hasSpecial: '!@#$&*',
messages: {
hasNumber: 'Password should contain at least one number',
hasSpecial: 'Password should have at least special'
}
},
But somehow the it was not working. So went debugging in your add-on's code, and found an issue.
I'm using version 1.2.7
, and the issue was on the file ember-validator/addon/mixins/pattern.js
.
In this part of the code, at the end of every regex you are doing the test with .test(value)
.
if (this.options.hasSpecial) {
if (typeof(this.options.hasSpecial) === 'string') {
specialTest = new RegExp('(?=.*[' + this.options.hasSpecial + '])').test(value);
} else if (this.options.hasSpecial.constructor !== RegExp) {
specialTest = this.options.hasSpecial.test(value);
} else {
specialTest = new RegExp('(?=.*[!@$%^&*()-+_=~`{}:;"\'<>,.|?])').test(value);
}
}
So this is making the variable specialTest
a boolean, right ? Because of .test(value)
result.
But later on in the code, you are doing this test:
} else if (this.options.hasSpecial && !specialTest.test(value)) {
this.pushResult(this.options.messages.hasSpecial);
}
And that's causing an error, because !specialTest.test(value)
is trying to call the method test
in a boolean variable, and not in a regex.
I think the best solution would be to remove the .test(value)
from where you define specialTest
.
I hope it helps! :)
Numeric validator - "notEqualTo" is not validating if 0 is passed.
Placeholder issue here. Currently this addon is untested, Adding tests will allow a safer upgrade path.
Hi! I've tried to make a custom validation that verifies if the property value is unique in all records on ember-data.
The problem is that the validators don't wait the findAll promises be resolved to validate de object. Any ideas on how can I make this?
The following restricts each validation object to allowing a maximum of one custom
property. We should expand this restriction to allow the ability to add multiple custom on-the-fly validators per validation object.
ember-validator/addon/mixin.js
Line 412 in f8e806b
This can easily be done by installing moment.js through npm and changing the path to the moment dist in the index.js file.
moment.js
deprecation warnings may be triggered during date validation. Issues may occur here https://github.com/anandts88/ember-validator/blob/master/addon/mixins/date.js#L49 and here https://github.com/anandts88/ember-validator/blob/master/ember-validator-non-cli.js#L241.
construction using a non-iso string is deprecated (see moment/moment#1407). One possible fix is to just always provide the native new Date(...)
constructor as the argument to moment(...)
.
moment(new Date("2016/01/01"));
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.