1 <sect2 id="zend.dojo.form.examples">
2 <title>Dojo 表单范例</title>
4 <example id="zend.dojo.form.examples.dojoform">
5 <title>使用 Zend_Dojo_Form</title>
8 和 <code>Zend_Form</code> 一起使用 Dojo的最容易的办法是利用 <code>Zend_Dojo_Form</code>,
9 直接使用或继承都可以。这个范例继承 Zend_Dojo_Form,并示范了所有 dijit 元素的用法。
10 它生成了四个子表单,并装饰了表单来使用 TabContainer,把每个子表单显示在它自己的 tab 上。
13 <programlisting role="php"><![CDATA[
14 class My_Form_Test extends Zend_Dojo_Form
17 * Options to use with select elements
19 protected $_selectOptions = array(
33 public function init()
35 $this->setMethod('post');
36 $this->setAttribs(array(
37 'name' => 'masterForm',
39 $this->setDecorators(array(
41 array('TabContainer', array(
42 'id' => 'tabContainer',
43 'style' => 'width: 600px; height: 500px;',
44 'dijitParams' => array(
45 'tabPosition' => 'top'
50 $textForm = new Zend_Dojo_Form_SubForm();
51 $textForm->setAttribs(array(
52 'name' => 'textboxtab',
53 'legend' => 'Text Elements',
54 'dijitParams' => array(
55 'title' => 'Text Elements',
58 $textForm->addElement(
62 'value' => 'some text',
72 'value' => '2008-07-05',
73 'label' => 'DateTextBox',
81 'label' => 'TimeTextBox',
89 'label' => 'CurrencyTextBox',
91 // 'currency' => 'USD',
92 'invalidMessage' => 'Invalid amount. Include dollar sign, commas, and cents.',
93 // 'fractional' => true,
95 // 'type' => 'currency',
102 'label' => 'NumberTextBox',
104 'invalidMessage' => 'Invalid elevation.',
105 'constraints' => array(
116 'label' => 'ValidationTextBox',
119 'invalidMessage' => 'Invalid non-space text.',
126 'label' => 'Textarea',
128 'style' => 'width: 200px;',
131 $toggleForm = new Zend_Dojo_Form_SubForm();
132 $toggleForm->setAttribs(array(
133 'name' => 'toggletab',
134 'legend' => 'Toggle Elements',
136 $toggleForm->addElement(
141 'label' => 'NumberSpinner',
144 'defaultTimeout' => 1000,
145 'timeoutChangeRate' => 100,
163 'label' => 'CheckBox',
164 'checkedValue' => 'foo',
165 'uncheckedValue' => 'bar',
173 'label' => 'RadioButton',
174 'multiOptions' => array(
182 $selectForm = new Zend_Dojo_Form_SubForm();
183 $selectForm->setAttribs(array(
184 'name' => 'selecttab',
185 'legend' => 'Select Elements',
187 $selectForm->addElement(
191 'label' => 'ComboBox (select)',
193 'autocomplete' => false,
194 'multiOptions' => $this->_selectOptions,
201 'label' => 'ComboBox (remoter)',
202 'storeId' => 'stateStore',
203 'storeType' => 'dojo.data.ItemFileReadStore',
204 'storeParams' => array(
205 'url' => '/js/states.txt',
207 'dijitParams' => array(
208 'searchAttr' => 'name',
216 'label' => 'FilteringSelect (select)',
218 'autocomplete' => false,
219 'multiOptions' => $this->_selectOptions,
224 'filterselectremote',
226 'label' => 'FilteringSelect (remoter)',
227 'storeId' => 'stateStore',
228 'storeType' => 'dojo.data.ItemFileReadStore',
229 'storeParams' => array(
230 'url' => '/js/states.txt',
232 'dijitParams' => array(
233 'searchAttr' => 'name',
237 $sliderForm = new Zend_Dojo_Form_SubForm();
238 $sliderForm->setAttribs(array(
239 'name' => 'slidertab',
240 'legend' => 'Slider Elements',
242 $sliderForm->addElement(
246 'label' => 'HorizontalSlider',
250 'discreteValues' => 11,
251 'intermediateChanges' => true,
252 'showButtons' => true,
253 'topDecorationDijit' => 'HorizontalRuleLabels',
254 'topDecorationContainer' => 'topContainer',
255 'topDecorationLabels' => array(
263 'topDecorationParams' => array(
264 'container' => array(
265 'style' => 'height:1.2em; font-size=75%;color:gray;',
268 'style' => 'height:1em; font-size=75%;color:gray;',
271 'bottomDecorationDijit' => 'HorizontalRule',
272 'bottomDecorationContainer' => 'bottomContainer',
273 'bottomDecorationLabels' => array(
278 'bottomDecorationParams' => array(
280 'style' => 'height:1em; font-size=75%;color:gray;',
289 'label' => 'VerticalSlider',
291 'style' => 'height: 200px; width: 3em;',
294 'discreteValues' => 11,
295 'intermediateChanges' => true,
296 'showButtons' => true,
297 'leftDecorationDijit' => 'VerticalRuleLabels',
298 'leftDecorationContainer' => 'leftContainer',
299 'leftDecorationLabels' => array(
307 'rightDecorationDijit' => 'VerticalRule',
308 'rightDecorationContainer' => 'rightContainer',
309 'rightDecorationLabels' => array(
317 $this->addSubForm($textForm, 'textboxtab')
318 ->addSubForm($toggleForm, 'toggletab')
319 ->addSubForm($selectForm, 'selecttab')
320 ->addSubForm($sliderForm, 'slidertab');
326 <example id="zend.dojo.form.examples.decorating">
327 <title> 修改已存在的表单来使用 Dojo </title>
330 通过使用 <code>Zend_Dojo::enableForm()</code> 静态方法,已存在的表单也可以使用 Dojo。
337 <programlisting role="php"><![CDATA[
338 $form = new My_Custom_Form();
339 Zend_Dojo::enableForm($form);
346 'autocomplete' => false,
347 'multiOptions' => array(
351 'orange' => 'Orange',
363 <programlisting role="php"><![CDATA[
364 class My_Custom_Form extends Zend_Form
366 public function init()
368 Zend_Dojo::enableForm($this);
376 当然,如果你可以那样做 ... 你可以并应该简单地修改类来继承 Zend_Dojo_Form,
377 它可以随时替换已经 Dojo-enabled 的 Zend_Form ...