Results 1 to 3 of 3

Thread: controller action fires on all button clicks

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    43
    Answers
    1

    Default controller action fires on all button clicks

    Hello, after doing ext js 3.4 for a few years I am starting Ext JS 4. I am writing a new application and have run into an odd issue. I have created a controller that has a controller action which is tied to a button click. So every time I click a button I have a function that is executed. My issue is that every time I click any button (including tabs), my function is executed. I specified the specific button I wanted this function tied to in the targetType field of the Config panel in archetict. I am sure I am making a nooby mistake, I just do not know where.

    My code is below, any ideas are most appreciated.

    Code:
    Ext.define('DPM.controller.searchPartyButtonClick', {
        extend: 'Ext.app.Controller',
        views: ['PartySearchButton'],
        buttonClick: function (button, e, eOpts) {
            var firstName = Ext.ComponentQuery.query('#firstNameField')[0].getValue();
            var middleName = Ext.ComponentQuery.query('#middleNameField')[0].getValue();
            var lastName = Ext.ComponentQuery.query('#lastNameField')[0].getValue();
            var address = Ext.ComponentQuery.query('#address1Field')[0].getValue();
            var city = Ext.ComponentQuery.query('#cityField')[0].getValue();
            Ext.Ajax.request({
                url: 'http://localhost:8080/DuplicatePartyManagement/servlet/searchParties',
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                jsonData: {
                    firstName: firstName,
                    lastName: lastName
                },
                success: function (response, opts) {
                    var obj = Ext.decode(response.responseText);
                },
                failure: function (response, opts) {}
            });
        },
        init: function (application) {
            this.control({
                "button": {
                    click: this.buttonClick
                }
            });
        }
    });

    sorry the code is all on one line, not sure why it would not format correctly
    Last edited by aconran; 15 Apr 2014 at 9:22 AM. Reason: fix code formatting

  2. #2
    Sencha User
    Join Date
    Aug 2013
    Posts
    31
    Answers
    10

    Default

    Hard to read the code but looking at one of my apps in the config of the function I have the 'controlQuery' set to #save where my button has an itemid of 'save'. Maybe you are missing that? My targetType is Ext.button.Button.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    43
    Answers
    1

    Default

    That was it! I had my controlQuery set to 'button' so the function was associated to every button in my application. I changed the controlQuery to be my buttons's itemId '#searchButton' and now it works great. Good call, thanks for the reply.

Posting Permissions

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