1
votes

I'm trying out the ember-validations mixin from DockYard. I have a NewUser object that looks like this:

App.NewUser = Ember.Object.extend(Ember.Validations.Mixin, {
  name: null,
  email: null,
  password: null,
  password_confirmation: null,

  validations: {
    name: {
      presence: true
    }
  },

  watchChanges: function() {
    // Live validations...
    this.validate();
  }.observes("name", "email", "password", "password_confirmation")
});

And I have a controller that has my submit method in it:

App.JoinController = Ember.ObjectController.extend({
  submit: function() {
    // Run validations again
    // Send to server if okay
    this.get("model").validate();
  }
});

And a route that links the model to the view:

App.JoinRoute = Ember.Route.extend({
  model: function() {
    return App.NewUser.create();
  }
});

(This is also a view that forwards the submit method along to the controller)

What I don't understand is how to wire from the Controller back to the model object to run .validate(). It seems like I should be able to do something in the controller's submit method like this.get("model").validate(), but that doesn't work. How should I go about making this work?

2

2 Answers

1
votes

Please try this

App.JoinController = Ember.ObjectController.extend({
   submit: function() {
      this.validate().then(function(){
         //if valid do actions
      }).catch(function(){
        //errors
     })
   }
});
0
votes

I guess you should try accessing the controller content property rather than the model, something like this should work:

App.JoinController = Ember.ObjectController.extend({
  submit: function() {
   // Run validations again
   // Send to server if okay
   this.get("content").validate();
  }
});

See here for a pseudo working demo.

Hope it helps.