1 <?xml version="1.0" encoding="UTF-8"?>
3 <!-- EN-Revision: 17166 -->
4 <sect2 id="zend.dojo.form.examples">
5 <title>Dojo Formサンプル</title>
7 <example id="zend.dojo.form.examples.dojoform">
8 <title>Zend_Dojo_Formの利用</title>
12 <classname>Zend_Form</classname>でDojoを利用する最も簡単な方法は、
13 <classname>Zend_Dojo_Form</classname>を利用することです。
14 この例では<classname>Zend_Dojo_Form</classname>の拡張と、
16 それは4つのサブ・フォームをつくって、TabContainerを利用するためにフォームを飾ります。
17 そして、それ自身のタブの中に各々のサブ・フォームを表示します。
20 <programlisting language="php"><![CDATA[
21 class My_Form_Test extends Zend_Dojo_Form
26 protected $_selectOptions = array(
40 public function init()
42 $this->setMethod('post');
43 $this->setAttribs(array(
44 'name' => 'masterForm',
46 $this->setDecorators(array(
48 array('TabContainer', array(
49 'id' => 'tabContainer',
50 'style' => 'width: 600px; height: 500px;',
51 'dijitParams' => array(
52 'tabPosition' => 'top'
57 $textForm = new Zend_Dojo_Form_SubForm();
58 $textForm->setAttribs(array(
59 'name' => 'textboxtab',
60 'legend' => 'Text Elements',
61 'dijitParams' => array(
62 'title' => 'Text Elements',
65 $textForm->addElement(
69 'value' => 'some text',
79 'value' => '2008-07-05',
80 'label' => 'DateTextBox',
88 'label' => 'TimeTextBox',
96 'label' => 'CurrencyTextBox',
98 // 'currency' => 'USD',
99 'invalidMessage' => 'Invalid amount. ' .
100 'Include dollar sign, commas, ' .
102 // 'fractional' => true,
103 // 'symbol' => 'USD',
104 // 'type' => 'currency',
111 'label' => 'NumberTextBox',
113 'invalidMessage' => 'Invalid elevation.',
114 'constraints' => array(
125 'label' => 'ValidationTextBox',
128 'invalidMessage' => 'Invalid non-space text.',
135 'label' => 'Textarea',
137 'style' => 'width: 200px;',
140 $editorForm = new Zend_Dojo_Form_SubForm();
141 $editorForm->setAttribs(array(
142 'name' => 'editortab',
143 'legend' => 'Editor',
144 'dijitParams' => array(
148 $editorForm->addElement(
153 'inheritWidth' => 'true',
157 $toggleForm = new Zend_Dojo_Form_SubForm();
158 $toggleForm->setAttribs(array(
159 'name' => 'toggletab',
160 'legend' => 'Toggle Elements',
162 $toggleForm->addElement(
167 'label' => 'NumberSpinner',
170 'defaultTimeout' => 1000,
171 'timeoutChangeRate' => 100,
189 'label' => 'CheckBox',
190 'checkedValue' => 'foo',
191 'uncheckedValue' => 'bar',
199 'label' => 'RadioButton',
200 'multiOptions' => array(
208 $selectForm = new Zend_Dojo_Form_SubForm();
209 $selectForm->setAttribs(array(
210 'name' => 'selecttab',
211 'legend' => 'Select Elements',
213 $selectForm->addElement(
217 'label' => 'ComboBox (select)',
219 'autocomplete' => false,
220 'multiOptions' => $this->_selectOptions,
227 'label' => 'ComboBox (remoter)',
228 'storeId' => 'stateStore',
229 'storeType' => 'dojo.data.ItemFileReadStore',
230 'storeParams' => array(
231 'url' => '/js/states.txt',
233 'dijitParams' => array(
234 'searchAttr' => 'name',
242 'label' => 'FilteringSelect (select)',
244 'autocomplete' => false,
245 'multiOptions' => $this->_selectOptions,
250 'filterselectremote',
252 'label' => 'FilteringSelect (remoter)',
253 'storeId' => 'stateStore',
254 'storeType' => 'dojo.data.ItemFileReadStore',
255 'storeParams' => array(
256 'url' => '/js/states.txt',
258 'dijitParams' => array(
259 'searchAttr' => 'name',
263 $sliderForm = new Zend_Dojo_Form_SubForm();
264 $sliderForm->setAttribs(array(
265 'name' => 'slidertab',
266 'legend' => 'Slider Elements',
268 $sliderForm->addElement(
272 'label' => 'HorizontalSlider',
276 'discreteValues' => 11,
277 'intermediateChanges' => true,
278 'showButtons' => true,
279 'topDecorationDijit' => 'HorizontalRuleLabels',
280 'topDecorationContainer' => 'topContainer',
281 'topDecorationLabels' => array(
289 'topDecorationParams' => array(
290 'container' => array(
291 'style' => 'height:1.2em; ' .
292 'font-size=75%;color:gray;',
295 'style' => 'height:1em; ' .
296 'font-size=75%;color:gray;',
299 'bottomDecorationDijit' => 'HorizontalRule',
300 'bottomDecorationContainer' => 'bottomContainer',
301 'bottomDecorationLabels' => array(
306 'bottomDecorationParams' => array(
308 'style' => 'height:1em; ' .
309 'font-size=75%;color:gray;',
318 'label' => 'VerticalSlider',
320 'style' => 'height: 200px; width: 3em;',
323 'discreteValues' => 11,
324 'intermediateChanges' => true,
325 'showButtons' => true,
326 'leftDecorationDijit' => 'VerticalRuleLabels',
327 'leftDecorationContainer' => 'leftContainer',
328 'leftDecorationLabels' => array(
336 'rightDecorationDijit' => 'VerticalRule',
337 'rightDecorationContainer' => 'rightContainer',
338 'rightDecorationLabels' => array(
346 $this->addSubForm($textForm, 'textboxtab')
347 ->addSubForm($editorForm, 'editortab')
348 ->addSubForm($toggleForm, 'toggletab')
349 ->addSubForm($selectForm, 'selecttab')
350 ->addSubForm($sliderForm, 'slidertab');
356 <example id="zend.dojo.form.examples.decorating">
357 <title>既存のフォームをDojoを使って変更する</title>
360 <methodname>Zend_Dojo::enableForm()</methodname>という静的メソッドを利用して、
361 既存のフォームをDojoを使って変更することもできます。
365 最初の例では既存のフォームの例を修飾して見せています。
368 <programlisting language="php"><![CDATA[
369 $form = new My_Custom_Form();
370 Zend_Dojo::enableForm($form);
377 'autocomplete' => false,
378 'multiOptions' => array(
382 'orange' => 'Orange',
391 あるいは、フォームの初期化でわずかな微調整をすることができます:
394 <programlisting language="php"><![CDATA[
395 class My_Custom_Form extends Zend_Form
397 public function init()
399 Zend_Dojo::enableForm($this);
407 もちろん、可能ならば、<classname>Zend_Dojo_Form</classname>を継承したクラスで単純に置き換えられるか、
409 そのクラスはすでにDojoが有効の<classname>Zend_Form</classname>の選択リストの代わりです。