0

I have a radiogroup as follows :

{
                    xtype: 'fieldset',
                    title: 'MÜŞTERİ TİPİ SEÇİMİ',
                    layout: 'anchor',
                    height: 80,
                    defaults: {
                        anchor: '100%'
                    },
                    items: [
                        {
                            xtype: 'radiogroup',
                            anchor: 'none',
                            layout: {
                                autoFlex: false
                            },
                            defaults: {
                                margin: '0 5 0 0'
                            },
                            cls: 'customer-radio-group',
                            items: [
                                {boxLabel: 'TÜM MÜŞTERİ', name: 'cstgrp', inputValue: '1'},
                                {boxLabel: 'HORECA', name: 'cstgrp', inputValue: '2'},
                                {boxLabel: 'TRADER', name: 'cstgrp', inputValue: '3'},
                                {boxLabel: 'SCO', name: 'cstgrp', inputValue: '4'},
                                {boxLabel: 'BRANŞ', name: 'cstgrp', inputValue: '5'},
                                {boxLabel: 'HEDEF GRUP', name: 'cstgrp', inputValue: '6'},
                                {boxLabel: 'CTG', name: 'cstgrp', inputValue: '7'}
                            ],
                            listeners: {
                                change: function (field, newValue, oldValue) {
                                    //var value = Ext.ComponentQuery.query('radiofield[name=cstgrp]');

                                    //console.log(newValue['cstgrp']);

                                    switch (newValue['cstgrp']) {
                                        case 1:
                                            break;
                                        case 2:
                                            break;
                                        case 3:
                                            break;
                                        case 4:
                                            break;
                                        case 5:
                                            break;
                                        case 6:
                                            break;
                                        case 7:
                                            console.log('CTG Secildi...');
                                            break;
                                    }
                                }
                            }
                        }
                    ]
                }

When I click the radio's, I can see selected radio input value in the console. But, change event that available in the listener doesn't fire, nothing happen. Am I doing wrong something?

Fix:
The value coming from radio is a string so that we should cast to integer or use string in the switch statement, thanks @rixo

        listeners: {
        change: function (field, newValue, oldValue) {
            //var value = Ext.ComponentQuery.query('radiofield[name=cstgrp]');

            //console.log(newValue['cstgrp']);

            switch (parseInt(newValue['cstgrp'])) {
                case 1:
                    break;
                case 2:
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    break;
                case 7:
                    console.log('CTG Secildi...');
                    break;
            }
        }
    }
Oğuz Çelikdemir
  • 4,990
  • 4
  • 30
  • 56
  • 2
    Your question isn't clear, I don't really understand what you're asking here. How are you seeing something in the console, if the `change` event doesn't fire? – Evan Trimboli Jul 25 '13 at 06:37
  • Dear Evan, I had a mistake which is value should be string format in `switch` statement therefore the change event didn't fire is because of that. – Oğuz Çelikdemir Jul 25 '13 at 07:41

1 Answers1

1

switch statements use strict comparisons in javascript. So you must use strings instead of integers in your cases:

case '7':
    console.log('...');
    break;
Community
  • 1
  • 1
rixo
  • 23,815
  • 4
  • 63
  • 68