Results 1 to 8 of 8

Thread: How do I add a new record to a Store from a form submit?

  1. #1

    Default How do I add a new record to a Store from a form submit?

    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!

  2. #2
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    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)

  3. #3

    Default

    On the other hand if you really want to then:
    Code:
            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.

  4. #4
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    Quote Originally Posted by cerad View Post
    On the other hand if you really want to then:
    Code:
            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 ?

  5. #5

    Default

    Can you clarify what you mean by wasteful?

  6. #6

    Default

    Quote Originally Posted by [email protected] View Post
    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.

  7. #7
    Sencha User
    Join Date
    Jan 2008
    Location
    Romania
    Posts
    23

    Default

    Quote Originally Posted by [email protected] View Post
    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.

  8. #8
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364

    Default

    Quote Originally Posted by chriss View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •