PDA

View Full Version : radiogroup へは setValues は効かない?



Tommy1969
20 Jun 2009, 10:53 PM
loadRecord や、setValues でフォームの初期化をしたいのですが、
radiogroup の中にあるラジオボタンには値が入らないようです。



<html>
<head>
<link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/ext-2.2.1/resources/css/ext-all.css" />
<script type="text/javascript" src="http://extjs.cachefly.net/builds/ext-cdn-771.js"></script>

<script type="text/javascript">
var simple = new Ext.FormPanel({
labelWidth: 75,
frame: true,
title: 'Simple Form',
width: 350,
defaults: {width: 230},
items: [
{xtype:'textfield', name: 'item1', fieldLabel: 'ITEM 1'},
{xtype:'radio', name: 'item2', fieldLabel: 'ITEM 2', boxLabel: 'V1', inputValue:1},
{xtype:'radio', name: 'item2', boxLabel: 'V2', inputValue:2},
{xtype:'radiogroup', fieldLabel: 'ITEM 3', items:[
{name: 'item3', boxLabel: 'VAL1', inputValue:1},
{name: 'item3', boxLabel: 'VAL2', inputValue:2},
]}
],
buttons: [
{text: 'Values', handler: function(btn, evt) {
var str = simple.getForm().getValues(true);
alert(str);
}}
]
});

Ext.onReady(function() {
simple.render(document.body);
simple.getForm().setValues({
item1: 'test',
item2: 2, // これは反映される。
item3: 2 // この値は反映されない…。(--;
});
});
</script>
</head>
<body>
</body>
</html>


やむを得ず、暫定的に getItem でラジオボタンを取得して…(略)…と、
別ロジックで値を埋め込む処理を実現しているのですが、他に良い手が
ありましたら、ご教示いただきたく…。

Tommy1969
21 Jun 2009, 12:19 AM
フォームで編集した後に使う updateRecord も radiogroup が反映されませんねぇ〜。

radiogroup を使って階層化すると、ちょっと面倒…。(--;

integra
22 Jun 2009, 11:40 PM
ExtJS 2.2.1のバージョンだと、
CheckboxGroupとRadioGroupのsetValueは未実装(Ext.emptyFn)なので、
別ロジックで埋め込む方式しかないと思います。
(Ext.form.BasicForm#loadRecord (http://extjs.com/deploy/ext-3.0-rc2/docs/source/BasicForm.html#method-Ext.form.BasicForm-loadRecord)はExt.form.BasicForm#setValues (http://extjs.com/deploy/ext-3.0-rc2/docs/source/BasicForm.html#method-Ext.form.BasicForm-setValues)を呼んでいるだけです。
また、BasicForm#setValuesはフィールドのsetValueを使用しています。わかりにくくてすみません。)

ExtJS 3.0 (RC2)だとCheckboxGroup#setValue (http://extjs.com/deploy/ext-3.0-rc2/docs/source/CheckboxGroup.html#method-Ext.form.CheckboxGroup-setValue)とRadioGroup#setValue (http://extjs.com/deploy/ext-3.0-rc2/docs/source/RadioGroup.html#method-Ext.form.RadioGroup-setValue)がきちんと実装されているようなので、
たぶん動くと思います。(試してないです。ごめんなさい)

3.0のソースコードを見る限り2.2.1でも動く気がするので、3.0のソースを使って継承して使ってみても良い気がします。

どちらにしてもExtJS3.0正式リリースが待ち遠しいです・・・。

Tommy1969
23 Jun 2009, 11:13 AM
情報、ありがとうございます。

投稿時は確認してもらいやすいように 2.2.1 でしたが、日頃は 3.0 RC2 を常用していて、現象に遭遇しました。ですので、おかしいなぁ〜と思って、軽く追試しましたところ、以下のことが分かりました。

1. 3.0 では確かに setValue が実装されている。
2. setValue が呼ばれるためには、radiogroup に name プロパティを追加する必要がある。
3. ただし、追加しても、今のところバグありで動かない。(--;

# setValue 仮引数に正しい値が入ってこないんですが、設計に踏み込まなきゃなら
# ない感じなので、これ以上、追いかけるのはパス!! >:)