Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing example showing how to manually update model in onbeforesave/onaftersave #736

Open
piotr-dobrogost opened this issue Jul 25, 2018 · 3 comments

Comments

@piotr-dobrogost
Copy link

piotr-dobrogost commented Jul 25, 2018

I can't find example showing how to manually update model in onbeforesave/onaftersave functions.

All I managed to find on this subject is the following statement at https://vitalets.github.io/angular-xeditable/#onbeforesave:

false: Success. But local model will not be updated and form will close. Useful when you want to update local model manually (e.g. server changed values).

It seems like allowing fourth type of return value (object?) in onbeforesave with the final value which the model should be set to would be useful. My need seems similar to what had been requested in x-editable project in issue Update value from validattion at vitalets/x-editable/issues/354.

Could you please add example showing this scenario?

@ckosloski
Copy link
Contributor

Is this what you are looking for?
One way to submit data on server is to define onbeforesave attribute pointing to some method of scope. Useful when you need to send data on server first and only then update local model (e.g. $scope.user). New value can be passed as $data parameter (e.g. <a ... onbeforesave="updateUser($data)">).

@piotr-dobrogost
Copy link
Author

No, it's not as there is no way to neither modify model in onbeforesave (it will be overwritten later with the original $data by the library) nor to return a value which the model should be set to.
In other words you can pass new value as $data parameter to onbeforesave but there is no way to pass modified (final) new value from onbeforesave to be used later by the library when updating the model. You are forced to make a side note inside onbeforesave what the new final value should be, return false and then inside onaftersave consult the side note you had made and possibly update model yourself accordingly.
Current flow: onbeforesave (take a side note with the final new value and return false) ➞ the library updates model with the new value (instead of the final new value) ➞ onaftersave (consult the side note and update model with the final new value yourself)
Desired flow: onbeforesave (return the final new value) ➞ the library updates model with the final new value
To sum it up, there's no way to update model right from onbeforesave now.

@ckosloski
Copy link
Contributor

Pull requests are welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants