Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with ember-idx-forms #5

Open
silverqx opened this issue Jun 13, 2015 · 1 comment
Open

How to use with ember-idx-forms #5

silverqx opened this issue Jun 13, 2015 · 1 comment

Comments

@silverqx
Copy link

Hi,

I want to ask, how to use this async button as submit button with ember-idx-forms?

Because when I click on async button, so first is called action, which is defined on on-click property and after that is called submit method at https://github.com/indexiatech/ember-forms/blob/master/addon/form.js#L52 and after that is called submit handler in the controller or route.

If you have ready some working example, pls paste it here.

Thank you for advices.

@silverqx
Copy link
Author

So I have resolved it with Deffered.

Wait and see if you have a better solution, before closing this issue.

import Em from "ember";

var _asyncSubmitDeffer = Ember.RSVP.defer();

export default Em.Controller.extend({

  actions: {

    submit: function() {
      var model = this.get('model');

      if (model.get('isDirty')) {
        model.save().then((data) => {
          _asyncSubmitDeffer.resolve();
          this.transitionToRoute('users')
        }).catch(function (reason) {
          _asyncSubmitDeffer.reject('Server error...');
        }).finally(() => {
        });
      } else {
        _asyncSubmitDeffer.resolve();
      }
    },

    asyncSumbit: function(setPromise) {
      return setPromise(_asyncSubmitDeffer.promise);
    }
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant