mercredi 16 décembre 2015

"Rolling back" error states in Ember template

My Ember controller reaches out to a JSONAPI service (using Ember Data) like so:

    model: function(params) {
        return Ember.RSVP.hash({
            data: this.store.query('recipe', params),
            ...
        });
    },

The params can contain a filter string that, if malformed, will cause the server to respond with HTTP code 422. I catch this in the same controller like so:

    actions: {
        error: function(error, transition) {
            console.log('Retrieval error: ' + error.message);
            this.controller.set('filterValid', false);
        }
    }

And in my handlebars template, I can then check the {{filterValid}} property of my controller and optionally apply a style to the <input> tag.

However: Once the filterValid property has been set to false, I cannot seem to find the right action or hook to then rollback/reset the property to true when the query doesn't fail. Since the above code is in my route, I don't have direct access to the controller in the model function. (Nor, based on the model/controller/template diagrams I've seen, should I.)




Aucun commentaire:

Enregistrer un commentaire