willCommit in invalid state


#1

The docs describe the invalid state as follows:

the record has invalid information and cannot send to the adapter yet.

A user in the app I’m building needs to be able to save a record again even if it has recently come back from the server as invalid (some properties are not editable by the user and so the record in some cases can’t become valid again via invalid.didSetProperty).

I’ve added the following to the invalid state and haven’t come across any problems yet, but does anyone know if there are any edge cases where this might present a problem?

willCommit: function(record) { record.transitionTo('inFlight'); },

record.transitionTo('uncommitted') apparently works as well but is a bit more tedious and seems like it would be more destructive than the first way.


#2

I’ve done this by calling model.send(“becameValid”) in the failure callback to save. I’m also curious about the “correct” approach here.


#3

Sending becameValid used to work for me in older version of ember-data, but not anymore.

Recent versions of ember-data add an errors attribute (using DS.Errors) to each record. Clearing out these errors before resubmitting works for me.

model.get("errors").clear()
model.save()