Search code examples
javascriptextjsextjs4

how to set radiogroup radiofield based on the json data extjs 4


hi forum member I am having one problem with setting the radiofield in the extjs 4

my form radiogroup xtype code is given below

{
  xtype: 'radiogroup',
  dataIndex: 'gender',
  margin: 5,
  fieldLabel: 'Gender',
  items: [{
    xtype: 'radiofield',
    name: 'gender',
    boxLabel: 'Male',
    inputValue:'0'
  }, {
    xtype: 'radiofield',
    name: 'gender',
    boxLabel: 'Female',
    inputValue:'1'
  }]
}

my json data I am receiving is

{
  "total": 1,
  "success": true,
  "employeedata": [{
     "username": "yaryan997",
     "surname": "Singh",        
     "firstname": "Yogendra",
     "gender": false
  }]
}

my employee list view has action column editEmployee which executes the below function

editEmployee:function(grid,no,rowindex,colindex,temp) {
        alert('Edit EMPLOYEE button pressed');
        var rec = grid.store.getAt(rowindex);
        var employeeid = rec.get('id');

        store = grid.getStore();
        store.load({
            params: {'employeeid':employeeid},
            scope: this,
            callback: function(records, operation, success) {
                //the operation object contains all of the details of the load operation
                console.log(records);
                this.getEmployeeEdit().editform=1;
                this.getEmployeeEditForm().loadRecord(rec);                 
                this.getEmployeeEdit().show();
            }
        });
        this.getEmployeeStore().load();
    },

based on the id the editEmployee view is shown. My edit Employee shows all the values correctly but only the problem is with the radiofield. They didn't show the selected value.

my json data I had provide you which comes as employeedata

I am not able to set the radiogroup gender based on the data i am receiving from the json.

please suggest me some solution for it.


Solution

  • First you should set inputValue to 'false' and 'true'. The second is the new design of a radiogroup. You will find the solution in my thread at the sencha forum See: http://www.sencha.com/forum/showthread.php?187185-Set-a-int-value-on-a-radiogroup-fails&goto=newpost

    The problem is that setValue is expecting a object which would only be the case if you had to datatypes for gender; one for male and one for female... And that's the point why I posted this as bug. Down the override code from my post.

    setValue: function (value) {
        if (!Ext.isObject(value)) {
            var obj = new Object();
            obj[this.name] = value;
            value = obj;
        }
        Ext.form.RadioGroup.prototype.setValue.call(this, value);
    }