PDA

View Full Version : Preventing a model update while using set



harrypottar
6 Apr 2012, 8:48 AM
I have a model attached to a form, I have a proxy in the model.

In the controller code when the forms submit button is pressed I crab the model attached to the form.

I use model.save passing in a parameter so my back end server knows how to deal with it.

All working very pleased.

However before I post the models data I need to set 5 elements of the model.

Each time I call set it tries to auto sync the data.

I tried adding model.beginEdit() which has helped and although I don't have a model.endEdit() it does post an auto sync after my last set method before I run my save.

Is there any way to turn this off, so that it 'only' updates the data when I call model.save()

Thanks

harry

scottmartin
6 Apr 2012, 9:15 AM
Try setting store.autoSync: false in your code. Perhaps the default is not working as expected?

Regards,
Scott.

harrypottar
6 Apr 2012, 9:17 AM
Thanks that helped it was not defined, I set it to false and it work. Very simple thank you.

el_chief
6 Apr 2012, 10:27 AM
disabling autosync is not that clever, as that's not the problem, plus, now you can't use autosync.

you should either set the model properties in bulk using beginEdit(), or temporarily disable autosync by calling suspendEvents() on the store:

http://jsfiddle.net/vZLZt/3/

harrypottar
6 Apr 2012, 10:42 AM
disabling autosync is not that clever, as that's not the problem, plus, now you can't use autosync.

you should either set the model properties in bulk using beginEdit(), or temporarily disable autosync by calling suspendEvents() on the store:

http://jsfiddle.net/vZLZt/3/

I understand what you're saying, but in this case I never want this store to auto sync. Its a one time form for posting data. It never receives data or updates data only every creates data.

Its not a standard form post either as I need the user to stay on the form as they may want to change some data and post again this would create new data.

I had used the beginEdit but could not stop it from posting twice, when I finished the edits and when I saved. I want it to only post when I call the method save.

Suspend Events posted twice as well when I saved and when I resumed Events again.

I wanted to run model save method passing in parameters and having a custom success and failure function to handle different responses from the server. I wanted to keep all this code in the control (mvc) outside of the store.

This store and model are used else where with different control to do something slightly different.