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

validate all inputs before save #20

Closed Leooo closed 9 years ago

Leooo commented 9 years ago
    SubmittingMixing.reopen({
      submit: function(event) {
        log("submit");
        log(this);
        this.$("input").blur();//triggers validations
        this._super(event);
      },
      _eventHandler: function(type){
        //hack to send the right method to the controller (destroy is already used): 'this' is undefined in destroyHandler
        //https://github.com/sir-dunxalot/ember-easy-form-extensions/issues/18
        if (type==="destroy") {type="destroyModel";}
        this._super(type);
      },
    });
sir-dunxalot commented 9 years ago

So, if I'm correct in understanding, there are two issues here:

  1. destroy is now a method on Ember.Controller
  2. this is undefined in the view's destroy handler
Leooo commented 9 years ago

Sorry, yes I added _eventHandler here but this more a hack to solve https://github.com/sir-dunxalot/ember-easy-form-extensions/issues/18#issuecomment-95507098.

Here I just added this.$("input").blur(); to force the validation of input fields before submitting: if I dont do this my form would'nt save but I don't see any error on the form (which is a form for a new model instance). I thought it may be useful to include the blur() line by default in ember-easy-form-extensions

sir-dunxalot commented 9 years ago

Ok, cool. I think there's a bigger issue here to do with the latest Ember release. This addon should show the error message on submit already (see source here). I think something has changed in the view layer or similar that's causing all these issue to combine.

I'll look into everything this weekend - keep sending the issues my way! Thanks.

sir-dunxalot commented 9 years ago

I've recreated this issue in another app. I think your solution is nice and simple. Another option is to refactor the Submitting mixin to work on the {{form-wrapper}} component - that whole set up needs a rethink. I am planning on rewriting a lot within the next couple of weeks.

sir-dunxalot commented 9 years ago

This is fixed with the major upgrade for Ember 1.11+ currently in prerelease. You can test the prerelease here. Please note the API for inputs has changed slightly from the original Easy Form syntax.

sir-dunxalot commented 9 years ago

Feedback for the new setup and options will be very much appreciated.

sir-dunxalot commented 9 years ago

This will be fixed by #37