-
31 Jul 2008 10:25 AM #1
Defining a button handler outside of a form panel definition
Defining a button handler outside of a form panel definition
Hello,
I have some code layed out similar to this:
The error I am getting is 'Ext.ComponentMgr.get("CRCType") is undefined' presumably because my function is defined before my formPanel, however if I define the function after the formPanel, it will tell me that the function is undefined.Code:function handleCodeReports(print){ var PostString = ''; PostString+='CodeType='+Ext.ComponentMgr.get('CRCType').getGroupValue()+'&'; if(print) PostString+= 'Action=Preview&'; else PostString+= 'Action=Preview&'; window.open('Reports/CodeReports.py?' + PostString ); } var CodeReports = new Ext.form.FormPanel({ autoScroll: true, frame: true, hidden: true, items: [{ xtype: 'fieldset', title: 'Code Type', autoHeight: true, items: [{ xtype: 'radio', checked: true, fieldLabel: 'Procedure', name: 'CRCType', id: 'CRCType', inputValue: 'Procedure' },{ xtype: 'radio', checked: false, fieldLabel: 'Diagnosis', name: 'CRCType', inputValue: 'Diagnosis' }] }], buttons: [{ text: 'Preview', formBind: true, handler:handleCodeReports(false) },{ text: 'Print', formBind: true, handler:handleCodeReports(true) }] });
Anyone have any suggestions on how to get around this?
-
31 Jul 2008 10:33 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,169
- Vote Rating
- 28
handler:handleCodeReports(false) means you're calling the method and assigning the result of that method to the reference.
handler:handleCodeReports means that you're setting the reference.
Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
31 Jul 2008 11:11 AM #3
Ok great, that makes sense, now how do I tell the button what parameter to pass into the function?
-
31 Jul 2008 11:54 AM #4
I quite often add a param to my button configs which store what actions I want to trigger in my handler:
the first param of the 'handler' is the btn component:Code:buttons: [{ text: 'Preview', formBind: true, handler:handleCodeReports(false), action: 'preview' },{ text: 'Print', formBind: true, handler:handleCodeReports(true), action: 'preview' }]
Code:... handler: function(btn){ switch(btn.action){ case 'preview' : break; ........... } } ...
-
31 Jul 2008 1:52 PM #5
the javascript function method createCallback() can be used to do what you want.
-
1 Aug 2008 3:42 AM #6
nice tip devnullthe javascript function method createCallback() can be used to do what you want.
.. don't know why I hadn't thought of using it there (I do in other places)!
If you require scope, you can use createDelegate ..
both are documented here:
http://extjs.com/deploy/dev/docs/output/Function.html


Reply With Quote