PDA

View Full Version : Set Radio Button as Selected Based On Ajax Response



rkanemeier
6 Nov 2012, 12:17 PM
I've been researching this for a while and haven't found an example or explanation that suits my needs. I have a form that allows the user to approve or deny a record in a database file. The approve/deny functionality is presented using a radio group. The user is presented a grid of records. They click on a record and it pops up a window containing a form. The form contains a radio group with Approve or Deny. When they choose one they can click Save to apply that change to the record. Here is the code for the field set used by the form panel that contains the radio group (with extraneous fields removed):



var reviewRecordFieldSet = Ext.create('Ext.form.FieldSet', {
id: 'reviewRecordFieldSet',
height: 225,
width: 410,
defaults: {
labelWidth: 100
},
items: [{
xtype: 'radiogroup',
fieldLabel: 'Approve/Deny',
itemId: 'approveDeny',
columns: 1,
vertical: true,
items: [{
xtype: 'radiofield',
boxLabel: 'Approve',
name: 'approval',
checked: true,
inputValue: 'A'
},{
xtype: 'radiofield',
boxLabel: 'Deny',
name: 'approval',
inputValue: 'D'
}]
}]
});


Prior to saving the approve/deny, I am using the following code to retrieve the value they selected (not sure if this is the kosher way to do it):



reviewRecordFormPanel.getValues().approval


However, when they click on a record, I want to "pre-set" the approve/deny button based on what is already in the file. I cannot seem to find a way to do this. I tried using several examples I've found on the internet, but most of them are using a handler to do the update (and that's not what I am attempting to do). Here is the code where I am loading the form:



function editReviewRecord (inRecord){
reviewRecordFormPanel.getForm().reset();
reviewRecordWindow.setTitle('Review Record');
reviewRecordFormPanel.down('#approveDeny').setValue(inRecord.get('APPROVEVAL'));
reviewRecordWindow.show();

}


This does not seem to work. Any suggestions on how to pre-set the selection of a radio group using the above editReviewRecord function?

(FYI, i just posted several responses to my own thread but it seems they are being approved. I didn't realize this until I posted my 3rd time). Here is the code I added to my radiogroup:



setValue:function(value) {
var val = Ext.isObject(value) ? value : {approval:value};
// console.log(this);
Ext.form.RadioGroup.prototype.setValue.call(this, val);
}


See this thread:

http://www.sencha.com/forum/showthread.php?187185-Set-a-int-value-on-a-radiogroup-fails&p=759988#post759988

(http://www.sencha.com/forum/showthread.php?187185-Set-a-int-value-on-a-radiogroup-fails&p=759988#post759988)

rkanemeier
6 Nov 2012, 12:55 PM
Ok, I think I may have resolved my own question, but I'm still too new to ExtJS to understand why this works:

I coded the setValue method of the radiogroup config:



xtype: 'radiogroup',
fieldLabel: 'Approve/Deny',
itemId: 'approveDeny',
columns: 1,
vertical: true,
items: [{
xtype: 'radiofield',
boxLabel: 'Approve',
name: 'approval',
inputValue: 'A'
},{
xtype: 'radiofield',
boxLabel: 'Deny',
name: 'approval',
inputValue: 'D'
}],
setValue:function(value) {
var val = Ext.isObject(value) ? value : {approval:value};
// console.log(this);
Ext.form.RadioGroup.prototype.setValue.call(this, val);
}


I found the solution here:

http://www.sencha.com/forum/showthread.php?187185-Set-a-int-value-on-a-radiogroup-fails&p=759988#post759988