angular-xeditable icon indicating copy to clipboard operation
angular-xeditable copied to clipboard

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

Open piotr-dobrogost opened this issue 7 years ago • 3 comments

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?

piotr-dobrogost avatar Jul 25 '18 15:07 piotr-dobrogost

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)">).

ckosloski avatar Jul 30 '18 18:07 ckosloski

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.

piotr-dobrogost avatar Jul 31 '18 07:07 piotr-dobrogost

Pull requests are welcome :)

ckosloski avatar Sep 04 '19 18:09 ckosloski