lcoq / ember-validations Goto Github PK
View Code? Open in Web Editor NEWEmber-Validations - An Ember.js library for handling object validations
License: MIT License
Ember-Validations - An Ember.js library for handling object validations
License: MIT License
With the NumericalityValidator, for example, the following code should works:
App.Pub = Ember.Object.extend(Ember.Validations, {
totalCount: 12,
validations: {
bars: {
lessThan: function() {
return this.get('totalCount');
}
}
});
In my app I needed to set itemController for #each helper and when I did that ember-validations cause js issue. To give some more context to the problem: http://stackoverflow.com/questions/20529723/controller-support-for-nested-model-data
Here is a jsbin link to demonstrate the issue:
http://jsbin.com/UROCObi/5/
I couldn't find cdnjs link to ember-validations so have pasted in whole lib there. Please have a look, you probably have better grasp of this issue and the reason behind it.
Thanks,
Dee
EDIT:
Sorry issued issue in wrong place, the ember validation I was using was taken from here : https://github.com/dockyard/ember-builds
If possible please delete this issue, because I couldn't delete it!
Apart from explicitly overriding the message with the right key, i didn't see anywhere in the source code to declaratively add custom error message
Ember.ValidationError.addMessage('blank', "can't be blank");
vs
foo {
presence: true
message: "This is a required field"
}
Hi there,
I've run into an issue where I'd like to validator to ensure the numericality of a property only if it is present? Right now the validator is invalidating the model if e.g. a blank string (as in filling a form) is assigned to property. Shouldn't the numericality validator first ensure the property is not blank and only then add the 'notNumber' error message for that property?
If you agree, I can submit a pull request, but I thought I'd ask first.
Thanks,
Sean
How can I define my own error messages?
This is such a cool library! ๐
Except, I don't think everyone is using Rake. Well, at least I don't and therefore can't try it :(
Is there a chance you could keep a dist version in the repository?
I believe there could be conflicts with other libraries, like ember-data which already have an errors
property.
I'm using node.js and would like the server and client to share the validation rules so they're on the same page. Any thoughts on how this can be accomplished?
When validating an object using validate()
, no propertyWillChange/DidChange callback is called.
It should because views should be automatically updated on validate
.
The README is almost completely written in code markup.
It's not pleasant-looking.
It should be possible to validate only one property, instead of validating all of them systematically
Unfortunately I couldn't create a working example with your tutorial because Ember.Object.extend
does not work, is it outdated?
So I have the following:
App.User = DS.Model.extend(Ember.Validations, {
validations: {
firstname: {
presence: true
}
}
}
My Controller which handles the user object which is created by user input (form elements):
App.IndexController = Ember.Controller.extend({
actions: {
register: function(){
var user = this.get('model');
user.validate();
}
}
});
At that moment I get the error: Uncaught TypeError: Object [object Object] has no method 'validate'
What have I done wrong? Bug? Thx for help.
For your information, why Ember.Object.extend
does not work, I get the following error then:
Assertion failed: Expected hash or Mixin instance, got [object Undefined] ember.js:394
DEPRECATION: Action handlers contained in an `events` object are deprecated in favor of putting them in an `actions` object (error on <App.ApplicationRoute:ember230>)
at Object.triggerEvent (http://localhost:9000/bower_components/ember/ember.js:30519:13)
at trigger (http://localhost:9000/bower_components/ember/ember.js:29641:16)
at handleError (http://localhost:9000/bower_components/ember/ember.js:29903:9)
at invokeCallback (http://localhost:9000/bower_components/ember/ember.js:8055:19)
at null.<anonymous> (http://localhost:9000/bower_components/ember/ember.js:8109:11)
at EventTarget.trigger (http://localhost:9000/bower_components/ember/ember.js:7878:22)
at http://localhost:9000/bower_components/ember/ember.js:8180:17
at Object.DeferredActionQueues.flush (http://localhost:9000/bower_components/ember/ember.js:5459:24)
at Object.Backburner.end (http://localhost:9000/bower_components/ember/ember.js:5545:27)
Hi, I want to create a tooltips
property that would contain processed error data from corresponding validators (key to key mapping). For that, I need to listen to any change in validation errors and update my tooltips hash.
The first thing I tried was attaching directly to the .errors
property on the model. However, I don't get notifications when its error arrays change and there is no equivalent to @each
for properties (barring some hacks I found online).
Then I tried attaching to some variation of validators.@each
construct. Unfortunately, I would need [email protected].@each
and that's a bit further than Ember allows.
Do you have any idea what I could attach or listen to? Some kind of global allErrors
property would be ideal for this, but I would take anything at this point.
It could be a good feature to have an option which make the validation automatically by listening each property that needs to be validated
I am just starting to use Ember and ember-validations. It would be helpful if you could provide an example of how validations are used in a template to provide visual feedback.
It would be really useful if the library offered the ability to specify scopes for a particular set of validations.
Example:
App.User = Ember.Object.extend(Ember.Validations, {
validations: {
scope: {
login: {
password: {
presence: true
}
}
editProfile: {
password: {
presence: true
}
passwordConfirmation: {
presence: true
}
}
}
// Normal, unscoped validations, which always applies.
name: {
presence: true
}
}
});
And then you validate the model like so:
var user = App.User.create({
username: 'user',
password: 'password',
passwordConfirmation: null
});
user.validate(); // true
user.validate('login'); // true
user.validate('editProfile'); // false
I grant that the example is not very plausible (one would not store a password in a model) but it does illustrate the general idea.
When FormatValidator
is the only validation attached to a property, when validating without a property value, an exception is thrown.
We'd like to define validations dynamically.. something like this:
validations: (->
if @get 'required'
value:
presence: true
).property 'required'
But if validations is defined as a computed property it's always empty (overridden by mixin somehow??)
Maybe im missing something obvious that is already available, but I'd like to bind to the validity of each property.
For example, to add an error class to a text field:
Thanks, and great work!
Trying to use a custom validate function:
validations: {
password: {
presence: true,
length: {
minimum: 6
},
format: {
validator: function (object, attribute, value) {
if (!Balanced.Utils.isValidPassword(value)) {
object.set('hasError', true);
return false;
}
}
}
}
}
But this is returning false
every-time I call model.validate()
even though I confirm that Balanced.Utils.isValidPassword()
is returning true
. What is the right way to do this?
Would it be possible to exit validation execution upon first error instead of executing all the registered validations of an attribute, as in some scenarios it is not required to show all the messages of an attribute in one go like scenarios where error messages are displayed next to the input control inline, please correct me if this kind of support is already present and your contribution to this framework is very much appreciated.
A typical scenario where are registering for something and have to enter your password or email address and then re enter to confirm
i'm close to having something. needed for a current project
Was it designed to work with ember-data as well?
We should not add objects in Ember
namespace directly.
A new namespace should be created.
item = @store.createRecord 'item'
# ...
item.get('isValid') # true
# item.save() #oops tries to save even if validation fails
# try to set isValid explicitly
item = @store.createRecord 'item'
item.set 'isValid', false
# now even validateProperty() passes, isValid on record is not updated
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.