PDA

View Full Version : [CLOSED] How to get selected value in RadioGroup?



vadym.f
Jul 31, 2013, 8:25 PM
Hi,

Please suggest how to port the 1.7 code getting the selected RadioGroup value on the client.

I have the following code in 1.7 that doesn't work under 2.2:



<ext:RadioGroup ID="RadioGroup1" runat="server">
<Items>
<ext:Radio ID="Radio1" runat="server" BoxLabel="Option 1" InputValue="1"></ext:Radio>
<ext:Radio ID="Radio2" runat="server" BoxLabel="Option 2" InputValue="2"></ext:Radio>
</Items>
<Listeners>
<Change Handler="alert(this.getValue().inputValue);" />
</Listeners>
</ext:RadioGroup>

vadym.f
Jul 31, 2013, 8:53 PM
I couldn't find an appropriate convenience method in Sencha docs. If it's there, please point it out to me.
Ext.form.RadioGroup (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.RadioGroup)
Ext.form.field.Radio (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Radio)

In the mean time, here's the workaround that I came up with:



<ext:RadioGroup ID="RadioGroup1" runat="server">
<Items>
<ext:Radio ID="Radio1" runat="server" BoxLabel="Option 1" InputValue="1"></ext:Radio>
<ext:Radio ID="Radio2" runat="server" BoxLabel="Option 2" InputValue="2"></ext:Radio>
</Items>
<Listeners>
<Change Handler="this.items.each(function(item){
if(item.checked){
alert(item.inputValue);
}
});" />
</Listeners>
</ext:RadioGroup>

Baidaly
Aug 01, 2013, 1:03 AM
Hello!

Please, look at the following sample:


<%@ Page Language="C#" %>

<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<script runat="server">
public void Page_Load(object sender, EventArgs e)
{
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET Examples</title>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:FormPanel runat="server" ID="FormPanel1">
<Items>
<ext:RadioGroup ID="RadioGroup1" runat="server" AutomaticGrouping="False">
<Items>
<ext:Radio ID="Radio1" runat="server" BoxLabel="Option 1" InputValue="1" Name="RadioValue"></ext:Radio>
<ext:Radio ID="Radio2" runat="server" BoxLabel="Option 2" InputValue="2" Name="RadioValue"></ext:Radio>
</Items>
<Listeners>
<Change Handler="" />
</Listeners>
</ext:RadioGroup>
</Items>
<Buttons>
<ext:Button runat="server" Text="Check second radio" Handler="
#{RadioGroup1}.setValue({ 'RadioValue': 2 })
"></ext:Button>
<ext:Button runat="server" Text="Show value" Handler="
alert(#{RadioGroup1}.getValue().RadioValue);
"></ext:Button>
</Buttons>
</ext:FormPanel>
</body>
</html>

vadym.f
Aug 01, 2013, 12:52 PM
Thanks Daulet!

After playing around with your code sample, I came to these two conclusions:


Setting AutomaticGrouping="False" is important
Non-integer InputValues don't work in this setup

Daniil
Aug 01, 2013, 1:09 PM
Hi Vadym,

Please use the getChecked method.

<Change Handler="alert(this.getChecked()[0].inputValue);" />

By the way, it is noted here.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.CheckboxGroup-method-getValue

vadym.f
Aug 01, 2013, 2:16 PM
Thanks for the pointers Daniil! Please mark this thread as closed.