Component to controller one-way communication

Hi,

I am working on a fairly complex Ember application and I am trying to split the app into separate components for better maintainability and also to move away from controllers as much as possible. I am quite new to ember, stiff fighting with some issues and I am not completely sure how to tackle some tasks.

The problem I am facing at the moment is a bottom-up communication between a component and the controller and specifically around validations. I have a component with some validations defined in it and input fields. I want to have a property in the controller, which resembles if the underlying component has valid data. Here is a jsbin with an example: JS Bin - Collaborative JavaScript Debugging

After quite a bit of experimenting I convinced myself that I need to use the mut helper and use an observer to update the controller’s property. A better solution will be to have a one-way binding from the component to the controller, but I couldn’t find a way to do that. Is that possible?

Also I had to explicitly update the mut property in the init of the component, which is really strange. Any ideas why is that needed? You can try to remove the init in the component and you will see how the binding breaks (controller no longer knows when the inputs are valid).

I will be thankful for any pointers and suggestions.

Thanks, Valentin

Hey Valentin! I have 1 minute here – sorry if I miss something important.

  • Why use a controller? Can’t the component validate its own model?
  • How about sending an action up to the controller instead of a mut?

Why use a controller? Can’t the component validate its own model?

Ultimately I need a controller as the top object to which the route goes to and it needs to pick the validation result from the components and handle the submit action.

See the updated jsbin for an example of it: JS Bin - Collaborative JavaScript Debugging

Basically there are a bunch of components with validation encapsulated in them and a controller-level action, which checks if everything is valid and makes the correct call to the server.

How about sending an action up to the controller instead of a mut?

Send an action on what event? Currently I observe the isValid property and do the update. The problem with this approach is the required init method (no idea why is that needed) and the mut helper (which is fine I guess… it would have been so much better if one-way binding could be used).

After playing with this more I am convinced this is a bug in the ember-validations gem. I filed an issue to them here: https://github.com/dockyard/ember-validations/issues/373