code_junkie

Ext RadioGroup - How to Access the value of selected radio button?

Nov 13th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. function createForm(elem) {
  2. var myForm2 = new Ext.form.FormPanel({
  3. renderTo:elem,
  4. width:425,
  5. frame:true,
  6. style:"margin: 10px auto 10px auto;",
  7. items: [{xtype:'fieldset',
  8. title: 'Contact Info',
  9. autoHeight:true,
  10. items :[new Ext.form.RadioGroup({
  11. fieldLabel: 'Main Phone',
  12. vertical: false,
  13. id:"mainPhone",
  14. items: [
  15. {boxLabel: 'Home', name: 'id-1', inputValue: 'H', checked:true},
  16. {boxLabel: 'Work', name: 'id-1', inputValue: 'W'},
  17. {boxLabel: 'Other', name: 'id-1', inputValue: 'O'}
  18. ]
  19.  
  20. }),
  21. new Ext.form.TextField({
  22. id:"frm_CreateCustomerHomePhone",
  23. fieldLabel:"Home Phone",
  24. width:275,
  25. allowBlank:true
  26. }),
  27. new Ext.form.TextField({
  28. id:"frm_CreateCustomerWorkPhone",
  29. fieldLabel:"Work Phone",
  30. width:275,
  31. allowBlank:true
  32. })
  33. new Ext.form.TextField({
  34. id:"frm_CreateCustomerOtherPhone",
  35. fieldLabel:"Other Phone",
  36. width:275,
  37. allowBlank:true
  38. })
  39. ]}]});
  40. }
  41.  
  42. myForm2.getForm().getValues()['id-1'];
  43.  
  44. var checkedItem = Ext.getCmp('mainPhone').getValue();
  45.  
  46. if (checkedItem == undefined) return '';
  47.  
  48. return checkedItem.getGroupValue();
  49. // The getGroupValue will return the value of the checked option in a group,
  50. // unfortunately, it only seems to work on the items and not the radiogroup
  51. // itself
  52.  
  53. myForm2.getForm().findField('id-1').getGroupValue();
  54.  
  55. Ext.getCmp("mainPhone").items.get(0).getGroupValue();
  56.  
  57. var radio = ...;
  58. var value = radio.inputValue;
  59.  
  60. function get_radio_value()
  61. {
  62. for( var i=0; i < document.myForm.mainPhone.length; i++ )
  63. {
  64. if( document.myForm.mainPhone[ i ].checked )
  65. {
  66. return document.myForm.mainPhone[ i ].value;
  67. }
  68. }
  69. }
Add Comment
Please, Sign In to add comment