Results 1 to 5 of 5

Thread: Help with some code

  1. #1
    Sencha User
    Join Date
    Jun 2008
    Location
    Frederick, MD
    Posts
    108

    Default Help with some code

    I just created my first application entirely in Sencha Architect. But I am having an issue that is not related to Architect. I am having a problem closing the window. I used to give each window a unique id and close the window using the id. I am trying to use the this.up method in the application.

    It works for one button but not the other. The one it does not work for is inside a form submit. If the form submits ok, I want to close the window. The one that works has the this.up inside the button listener. The one in the form gives the error that up is not a function.

    If someone can point me in the right direction that would be very helpful. Below is the code (I bolded the one that is not working):

    Code:
    items: [
                            {
                                xtype: 'button',
                                text: 'Save',
                                icon: '/images/save.png',
                                listeners: {
                                    click: function() {
                                                                            
                                        var form = this.up('form').getForm();
                                        form.submit({
                                            url:'/data/actions.php',
                                            params: {dataset: 'listData', SID: SID},
                                            success: function(form, action) {
                                                   Ext.getStore('ListDataStore').load();
                                                   this.up('window').close();
                                            },
                                            failure: function(form, action) {
                                                switch (action.failureType) {
                                                    case Ext.form.action.Action.CLIENT_INVALID:
                                                        Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                                                        break;
                                                    case Ext.form.action.Action.CONNECT_FAILURE:
                                                        Ext.Msg.alert('Failure', 'Could Not Communicate With Server.');
                                                        break;
                                                    case Ext.form.action.Action.SERVER_INVALID:
                                                       Ext.Msg.alert('Unable To Save New List Item', action.result.msg);
                                                    
                                                   }
                                            }
                                        })
                                    }
                                }
                            },
                            {
                                xtype: 'button',
                                text: 'Cancel',
                                icon: '/images/delete.png',
                                listeners: {
                                    click: function() {
                                        this.up('window').close();
                                    }
                                }
                            }
                        ]
    Mike

  2. #2
    Sencha User
    Join Date
    Jan 2012
    Posts
    17
    Answers
    1

    Default

    Hi

    Replace
    Code:
     this.up('window').close();
    with
    Code:
     form.up('window').close();

  3. #3
    Sencha User
    Join Date
    Jun 2008
    Location
    Frederick, MD
    Posts
    108

    Default

    That did not work. It still says .up is not a function.

  4. #4

    Join Date
    Feb 2011
    Location
    Chisinau, Moldova
    Posts
    316
    Answers
    64

    Default

    It didn't because the form argument from the success callback is a basic form, which does not have an "up" method. You can either rename this argument to "basicform", so that you will have access via closure to the "form" variable and then "form.up('window').close();" will work, or add a "scope: this" option to the submit config, so that inside the success callback function the scope will be the button, and in this case "this.up('window').close();" will work.

  5. #5
    Sencha Premium User
    Join Date
    Apr 2009
    Location
    Raalte, Netherlands
    Posts
    253
    Answers
    7

    Default

    Code:
    listeners: {
        scope: this,
        click: function() {
           var form = this.up('form').getForm();
           form.submit({
                url:'/data/actions.php',
                params: {dataset: 'listData', SID: SID},
                success: function(form, action) {
                   Ext.getStore('ListDataStore').load();
                   this.up('window').close();
                                            },
    
    or:

    Code:
    listeners: {
        click: function(btn, e) {
           // assuming that the ownerCt is the window, otherwise btn.ownerCt.ownerCt (but it is ugly)
           var win = btn.ownerCt; 
           var form = win.down('form').getForm();
           form.submit({
                url:'/data/actions.php',
                params: {dataset: 'listData', SID: SID},
                success: function(form, action) {
                   Ext.getStore('ListDataStore').load();
                   win.close();

Similar Threads

  1. How to sync code on code viewer of Sencha Architect and real source code ?
    By veeva_hiroyuki_nagata in forum Sencha Architect 4.x: Q&A
    Replies: 1
    Last Post: 30 Nov 2016, 5:44 AM
  2. Replies: 1
    Last Post: 27 Mar 2015, 3:04 PM
  3. Replies: 5
    Last Post: 21 Dec 2012, 6:27 AM
  4. [CLOSED] Code View should highlight related code for item selected in Project Inspector
    By gatherworks in forum Sencha Architect 2.x: Bugs
    Replies: 1
    Last Post: 5 Apr 2012, 9:29 AM
  5. Replies: 5
    Last Post: 29 Oct 2008, 2:24 AM

Posting Permissions

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