We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 275 Posts
    Hello,

    I have strange/unexpected behaviour from a combo box.

    The following combo box is on a Modx FormPanel:
    xtype: 'my-combo'
    ,fieldLabel: 'Property'
    ,emptyText: 'Select a property to view calendar...'
    ,allowBlank: true
    ,name: 'property'
    ,listeners: {
          'select': {fn:this.filterMonths(id),scope:this}
    }
    


    The registered listeners listens for select events on the combo. The function looks like this:
    	,filterMonths: function(id) {
    		alert('About to toddle off to the server...');
            MODx.Ajax.request({
                url: Tariffs.config.connector_url
                ,params: {
                    action: 'mgr/calendar/getmonth'
                    ,property: id
                }
            });
    	}
    


    Although it works - but not as expected.

    The function filterMonths() only gets called once, when the CMP initially loads. I see the alert, I see the expected log entries created by getmonth.php, but after that... nothing. How much I select from that combo, the event doesn’t get fired and no Ajax calls are being done...

    I’m a bit perplexed, to be honest. I would expect that function to be called upon each time I change the selected item of the combo???
      MODx Revolution / MAMP / OS X
      • 27519
      • 275 Posts
      Oh, bugger... please ignore. Too quickly to the forum, not enough debugging.
        MODx Revolution / MAMP / OS X
        • 28215
        • 4,149 Posts
        For those reading, you should be using:

        ,listeners: {
              'select': {fn:this.filterMonths,scope:this}
        }


        Instead of fn:this:filterMonths(id)
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 27519
          • 275 Posts
          Yep, that was the error.

          Thanks for pointing that out Shaun!
            MODx Revolution / MAMP / OS X
            • 28215
            • 4,149 Posts
            No problem; the reason why is that you’re passing in a *reference* to the function - not the result of the function. Adding the () and parameters to the method tells JS to execute the method, and return the result and assign that to the fn: property. This isn’t what you want - you want to assign the method *itself* to the fn: property. So you don’t pass it with the (), causing JS to pass a pointer to the method instead.
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 27519
              • 275 Posts
              Quote from: splittingred at Oct 12, 2010, 08:45 AM

              No problem; the reason why is that you’re passing in a *reference* to the function - not the result of the function. Adding the () and parameters to the method tells JS to execute the method, and return the result and assign that to the fn: property. This isn’t what you want - you want to assign the method *itself* to the fn: property. So you don’t pass it with the (), causing JS to pass a pointer to the method instead.

              Just one more and I’ll shut up ... grin

              Say I’d wanted to pass a parameter with that function? Is that possible?
                MODx Revolution / MAMP / OS X
                • 28215
                • 4,149 Posts
                Either just wrap it in a function:

                fn: function() { return this.filterMonths(params,here,like,so); }


                or use ExtJS’s createDelegate.
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com