PDA

View Full Version : How do I add a new record to a Store from a form submit?



Ranma13
4 Feb 2010, 2:05 PM
I have a form that, on submit, I'd like to add a new record to a store instead of POSTing to a URL. This way, I can use the store to do the save instead of the form. Can someone provide an example of how I can do this? Thanks!

jay@moduscreate.com
4 Feb 2010, 2:20 PM
i would elect to use the form to submit, and upon "success" add the record dynamically to the store, with the *returning* data from the server. I did this a lot in the application in my book.

see http://app.extjsinaction.com/ (any user/any pass)

cerad
4 Feb 2010, 2:37 PM
On the other hand if you really want to then:


var values = this.getForm().getValues();
var record = new store.recordType(values);
store.add(record);
store.save();

Often wondered why forms didn't use a store for data storage. Especially with DirectStores.

jay@moduscreate.com
4 Feb 2010, 6:00 PM
On the other hand if you really want to then:


var values = this.getForm().getValues();
var record = new store.recordType(values);
store.add(record);
store.save();

Often wondered why forms didn't use a store for data storage. Especially with DirectStores.

because it's watsteful ?

Ranma13
5 Feb 2010, 7:41 PM
Can you clarify what you mean by wasteful?

cerad
6 Feb 2010, 5:51 AM
because it's watsteful ?
Exactly. Why develop two independent means of sending records back and forth between the server. Would have been much more efficient to have one way of dealing with flat records. So I wonder why they chose the wasteful approach?

Why should form load/submit behave differently than store load/save?

Granted that some forms need to post files. But files are handled differently regardless.

From a developer perspective, GridEditors and Forms should be the same. It's just that a form (usually) only has one record.

I also saw a note somewhere that some sort of relationship between stores might be implemented. Be a shame if a form could not take advantage of this capability.

chriss
8 Feb 2010, 10:43 AM
i would elect to use the form to submit, and upon "success" add the record dynamically to the store, with the *returning* data from the server. I did this a lot in the application in my book.

see http://app.extjsinaction.com/ (any user/any pass)

I used to make the same thing, but i don't think that this is one of the best practices. Considering that one user adds some records, and then deletes or updates them, you'll end with a lot of unnecessary server calls. You could take for example the source control tools and make a global check in when you're sure that nothing else needs to be modified.

jay@moduscreate.com
8 Feb 2010, 10:45 AM
I used to make the same thing, but i don't think that this is one of the best practices. Considering that one user adds some records, and then deletes or updates them, you'll end with a lot of unnecessary server calls.

Really? What would you suggest as a best practice? The problem isn't data concurrency, it's how to submit and add records to grids.