alexhisen / mobx-schema-form

MIT License
22 stars 6 forks source link

wip: returning model.save() result at SaveButton onSave prop #3

Closed rsptarnas closed 5 years ago

alexhisen commented 5 years ago

The problem with this PR is the FormStore save() method is supposed to return false when no save was performed and true when it was regardless of validation state - https://alexhisen.gitbooks.io/mobx-forms/formstore-save.html. So, with this PR validateAndSave() could return false and there could be no errors (just nothing new to save) and it can return true and there could still be both server-returned errors and unsaved fields in error (while others were saved). FormStore is designed for aggressive preservation of data and doesn't have a single binary is valid / is invalid differentiation. Instead onBefore/AfterSave callbacks can deal with fields that are invalid.

Currently validateAndSave() doesn't really support server-side validation failures but it won't properly support them with this PR either. So, what was the goal for this PR and having the return value of model.save() exposed to the Save button?

Most likely you can instead just handle it in the onAfterSave callback or look directly at model.status.errors.

Also, keep in mind that FormStore 'server' methods are your own and they can do anything and server may not actually represent the server but a local data persistence layer and actual server communications can be a sort of side-effect that occurs in onSave.