I have a form where visitors can leave a comment with a typical "I accept the ToS" checkbox and link. The link transitions to a new route with the ToS text.
I create my comment record when the route with the form is loaded. I do this so my template can load the right default settings (there is a gender radio button for example that is set to the right value thanks to Ember data attrs).
App.CommentRoute = Ember.Route.extend({
model: function() {
return this.store.createRecord('comment');
}
actions: {
create: function(comment) {
comment.save();
}
}
});
The comment model:
App.Comment = DS.Model.extend({
body: DS.attr("string"),
gender: DS.attr("string", {defaultValue: "M"}),
});
And the template:
<form {{action "create" this on="submit"}}>
...
</form>
Now, when people click the back button from the ToS page all the form fields are emptied as a new model is loaded. I do want this behavior once the form is saved or if you reload it but obviously not when using the back button. I worked around this by keeping a global state but feel there should be a better way. Any tips?