Closed ivan-leschinsky closed 10 years ago
Sorry i dont understand the question,
Can you elaborate ?
Please provide a jsbin example or more code samples & error messages,
Thanks.
Here is the example I do as it says. With my model:
App.Company = Ember.Model.extend
id: Ember.attr
name: Ember.attr
email: Ember.attr
App.Company.reopen
validations:
name:
presence: true
But it doesn't work. There are no any error messages in js console. Forms (templates and actions) are working but without validations. When I press "submit" - the action, that I've specify just runs, without any validations.
+1 here is a JsBin: http://jsbin.com/pexolude/14/edit Validation doesnt work.
@ivan-leschinsky I just checked, it works pretty well, Please provide a jsbin sample, but in general, if your model.isValid returns true, then it means the form is validated, so check this variable on the model level,
@BenjaminHorn your code sample is wrong because you don't use the Person
model you've created with the validations rules set, in the controller you do:
model: function() {
return Ember.Object.create({
people: [{
firstName: 'Hans',
lastName: 'Meier'
}]
});
you should change it to something like:
this.store.createRecord('person', {
firstName: 'Hans',
lastName: 'Meier'
});
Thanks.
Closing but feel free to re-open if needed.
I'm quite new to Ember, but beside that with some effort everything works (Also thanks for the great Bootstrap for Ember), I'm really lost now after some seriously serious trying to get these forms under control. (:facepunch: my face)
Beside that it obviously works for other people, I seem to got stuck the very same way as @ivan-leschinsky and @BenjaminHorn. (If in the meantime you guys should've found out why, I would be thankful for some insight).
And to shorten this post: If someone can bring the posted JSBin to live, that would be it, as I completely failed to make it working, which somehow gives me hope that there's something somewhere that not only I don't see.
Btw., what's the reason that the "Submit" button on JSBin is deactivated?
The validation itself seems okay (tested on my local app), because when I add the validation to the controller, and give the validated properties fixed values like name: '1234', the validation on submit fails (4 chars), and with name: '12345' succeeds (5 chars).
So the problem doesn't seem to be the validation, but the binding between the form fields (Like
Out of total hopelessness (With big bear tears!) I just tried to insert a basic {input type="text" value=name}} to my template and this worked instantly.
I even tried to imitate the Sample to the extend that I made use of {{render}}, as I guessed it might've to do with the separate template render calls and their explicit model, but no change.
Any ideas?
@zypo This jsbin is broken, its not really using the model that is being validated,
Here is a working example: http://jsbin.com/pexolude/2/edit
Let me know if it works for u :)
@asaf Yeah, I was well aware that the former JSBin was broken, but I should've been able to make it work, but for some reason I didn't (Which I'll finally figure out now, thanks to your example), and it drove me nuts.
The working example looks still so simple that I would think that I did this at least x times. ;)
If I figure out any significant reason beside total mental bluntness on my side, I'll post it here, just in case someone else runs into the same. :)
Thanks again! And if I can contribute some, I'll do. Just experimenting with Select2 for Ember, which might be a nice (optional, as somehow bloaty) add-on to Ember Forms and it's even already "Bootstrap3ed".
Okay, as "promised", that's what all went wrong on my first run:
setupController: function(controller) {
// controller.set('test', this.store.find('test', '1'));
// alert(test.get('title'));
}
App.MyRoute = Ember.Route.extend({
mymodel: function() {
{{em-input property="person.firstName" label="First Name" placeholder="Please enter first name."}}
So, yeah, Ember newbies can run into quite some surprises.
Cheers, always take a very detailed look of what code you've there in front of you, and happy Embering! :)
How can I transfer it to Ember-model? I have some projects with ember-model. I think that Ember-data more compex. Now I have smth like:
But the validation does not work when I add them to the model with 'reopen'