(extjs) Get the selected switch value in the form. Do not return value

I followed the basic procedures for getting the selected form value of my switch.

.... xtype: 'radiofield', name: 'timespan', id: 'timespan', value: 7, checked: true, fieldLabel: 'Time Span', boxLabel: '7 days' }, { xtype: 'radiofield', name: 'timespan', value: '30', fieldLabel: '', labelSeparator: '', hideEmptyLabel: false, boxLabel: '30 days' }, { xtype: 'radiofield', name: 'timespan', value: '60', fieldLabel: '', labelSeparator: '', hideEmptyLabel: false, boxLabel: '60 days' }, { xtype: 'radiofield', name: 'timespan', value: 'all', fieldLabel: '', labelSeparator: '', hideEmptyLabel: false, boxLabel: 'All' .... 

I used methods like:

 Ext.getCmp('filter_form').getForm().getValues()['timespan'] 

But when I run this on the console, instead of getting the value of the selected button, I get the word on . What gives?! I tried several different combos getValues, getForm, etc., but I always get on or true or false . What's going on here?

+6
source share
2 answers

I thought! Turns out there is an error in my extjs code example!

I changed value to inputValue . inputValue taken from Sencha Docs:

The value that should go to the value of the generated input element is the attribute and should be used as the parameter value when sending as part of the form. Default: 'on'

Yeah !! Since I did not specify a "real" value, it was on by default.

Be careful when using extjs examples / examples!

+3
source

try setting the inputValue property of the radio. Which is the value that should be included in the generated attribute value of the input element and should be used as the parameter value when sending as part of the form.

 { xtype : 'radiofield', name : 'timespan', inputValue : '30', hideEmptyLabel : false, boxLabel : '30 days' } 

then it can be accessed as

 Ext.ComponentQuery.query('[name=timespan]')[0].getGroupValue(); 

contact docs getGroupValue

+4
source

Source: https://habr.com/ru/post/924764/


All Articles