sir-dunxalot / ember-easy-form-extensions

Manages form submission in the controller/component and route layers of Ember apps
MIT License
28 stars 14 forks source link

Using easyForm in route #40

Closed antoniusostermann closed 8 years ago

antoniusostermann commented 9 years ago

(Ember: 1.13.3, EmberData: 1.13.5, easyFormExtensions: 1.0.2)

As you may know, using controllers is deprecated in ember. Because of this I never create any controller, doing everything in routes or components (like stated in http://thetechcofounder.com/getting-started-with-ember-js-using-ember-cli/). If I use this extension in my route like this:

import Ember from 'ember';
import FormMixin from 'ember-easy-form-extensions/mixins/controllers/form';

export default Ember.Route.extend(FormMixin, {
  model: function() {
    return this.store.find('post');
  },

  actions: {

    cancel: function() {
    },

    save: function() {
    },
  }
});

with this template:

{{#form-wrapper}}
  {{#form-controls legend='Write a new post'}}

    {{!--model.title--}}
    {{input-group property='title'}}

    {{!--model.description--}}
    {{input-group property='body' type='textarea'}}

  {{/form-controls}}

  {{!--Submit and cancel buttons--}}
  {{form-submission}}
{{/form-wrapper}}

I currently get

TypeError: formController is null

linking to

   addBindingForErrors: on('didInitAttrs', function () {
      var property = this.get('property');

      Ember['default'].assert('You must set a property attribute on the {{error-field}} component', property);

      var formController = this.get('formController');
      var validations = formController.get('validations');

Could you maybe give an example on how to use this with routes (also to make it compatible with future ember versions)?

Truffula commented 9 years ago

AFAIK you need to keep using controllers until routable components land. Ember.Route::renderComponents won't be in the API for one or two more versions.

sir-dunxalot commented 9 years ago

The recent refactor was written with this exact use case in mind so it's likely that there is some property reference amiss rather than an architectural issue. My guess is that it's related to this code.

I'll need to make a test locally before I can confirm that though. We'll also need to increase the acceptance test coverage for this 'component usage' because this library is lacking that (in fact more acceptance tests need to be added in general).

sir-dunxalot commented 9 years ago

Perhaps we could also have a mixin at the path ember-easy-form-extensions/mixins/components/form.js to easy future upgrading - this would just export the controller mixin.

sir-dunxalot commented 8 years ago

Fixed with #48 (released as 2.0.0).