Results 1 to 3 of 3

Thread: Form - Store - CRUD operation

  1. #1
    Sencha User
    Join Date
    Dec 2008
    Location
    France
    Posts
    321
    Answers
    5

    Default Answered: Form - Store - CRUD operation

    Hello,

    I've a form.
    After entering datas into the form, i want to perform a Crud operation with a store.
    I've searched and found some examples and explanations, but i'm facing an error.

    OnRender of the form, i create and load a new record into the form. It's OK
    After clicking the "save" button of the form, i've the error : store.add is not a function

    Code:
        onFormRender: function(component, eOpts) {
            var formPanel = this.getView(),
                form = formPanel.getForm(),
                newRecord = Ext.create('model.annuaire_cadre');
    
            form.reset();
    
            form.loadRecord(newRecord);
        };
    
        save: function(button, e, eOpts) {
            var form = this.getView().getForm(),
                record = form.getRecord(),
                store = MY_APP.store.annuaire.AnnuaireCadre;
    
            if (form.isValid()) {
                form.updateRecord();     <== it's OK, i can see in Firefox Webtools that the record is set with the datas entered into the form
                if (record.phantom) {
                    store.add(record);      <== error appears here : store.add is not a function, store appears as a constructor : store:constructor()
                }
                store.commitChanges();
           }
       };

  2. Have you tried store = Ext.getStore('annuaire.AnnuaireCadre'); ?

  3. #2
    Sencha MVP Team Member
    Join Date
    Sep 2016
    Location
    Kennewick, WA
    Posts
    153
    Answers
    15

    Default

    Have you tried store = Ext.getStore('annuaire.AnnuaireCadre'); ?

  4. #3
    Sencha User
    Join Date
    Dec 2008
    Location
    France
    Posts
    321
    Answers
    5

    Default

    That's it !
    Thanks


    I did a more simple code, without onFormRender
    Code:
    var form = this.getView().getForm(),
        values, model,
        store = Ext.getStore('annuaire.AnnuaireCadre');
    
    if (form.isValid()) {
        values = form.getValues();
        model = Ext.create('model.annuaire_cadre', values);
        store.add(model);
        store.sync({
            success: function(batch, options) {
                response = Ext.decode(batch.operations[0].getResponse().responseText);
                Ext.Msg.show({
                    title: response.title,   //<== title comes from the server side
                    msg: response.message,   //<== message comes from the server side
                    buttons: Ext.Msg.OK,
                    scope: this,
                    icon: Ext.Msg.INFO
                });
            }
    
    // the failure is done in the exception of the proxy store
    
        });
    } else {
        Ext.Msg.show({
            title: 'Error',
            msg: 'There is errors in the form',
            buttons: Ext.Msg.OK,
            animateTarget: button,
            scope: this,
            icon: Ext.Msg.ERROR
        });
    }

Similar Threads

  1. GRID CRUD operation example
    By gpradeepjain in forum Ext JS 6.x Q&A
    Replies: 5
    Last Post: 18 Jul 2017, 3:56 AM
  2. Replies: 2
    Last Post: 20 Jul 2011, 12:51 AM
  3. Store CRUD operation
    By chanrana in forum Sencha Touch 1.x: Discussion
    Replies: 0
    Last Post: 7 Jan 2011, 7:56 AM
  4. JSON Store: no CRUD operation if a record changes
    By astuteq in forum Sencha Ext JS Q&A
    Replies: 7
    Last Post: 25 Nov 2010, 3:10 PM

Posting Permissions

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