1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect2 id="zend.dojo.form.examples">
4 <title>Dojo Form Examples</title>
6 <example id="zend.dojo.form.examples.dojoform">
7 <title>Using Zend_Dojo_Form</title>
10 The easiest way to utilize Dojo with <classname>Zend_Form</classname> is to
11 utilize <classname>Zend_Dojo_Form</classname>, either through direct usage or
12 by extending it. This example shows extending <classname>Zend_Dojo_Form</classname>, and
13 shows usage of all dijit elements. It creates four sub forms, and
14 decorates the form to utilize a TabContainer, showing each sub form
18 <programlisting language="php"><![CDATA[
19 class My_Form_Test extends Zend_Dojo_Form
22 * Options to use with select elements
24 protected $_selectOptions = array(
38 public function init()
40 $this->setMethod('post');
41 $this->setAttribs(array(
42 'name' => 'masterForm',
44 $this->setDecorators(array(
46 array('TabContainer', array(
47 'id' => 'tabContainer',
48 'style' => 'width: 600px; height: 500px;',
49 'dijitParams' => array(
50 'tabPosition' => 'top'
55 $textForm = new Zend_Dojo_Form_SubForm();
56 $textForm->setAttribs(array(
57 'name' => 'textboxtab',
58 'legend' => 'Text Elements',
59 'dijitParams' => array(
60 'title' => 'Text Elements',
63 $textForm->addElement(
67 'value' => 'some text',
77 'value' => '2008-07-05',
78 'label' => 'DateTextBox',
86 'label' => 'TimeTextBox',
94 'label' => 'CurrencyTextBox',
96 // 'currency' => 'USD',
97 'invalidMessage' => 'Invalid amount. ' .
98 'Include dollar sign, commas, ' .
100 // 'fractional' => true,
101 // 'symbol' => 'USD',
102 // 'type' => 'currency',
109 'label' => 'NumberTextBox',
111 'invalidMessage' => 'Invalid elevation.',
112 'constraints' => array(
123 'label' => 'ValidationTextBox',
126 'invalidMessage' => 'Invalid non-space text.',
133 'label' => 'Textarea',
135 'style' => 'width: 200px;',
138 $editorForm = new Zend_Dojo_Form_SubForm();
139 $editorForm->setAttribs(array(
140 'name' => 'editortab',
141 'legend' => 'Editor',
142 'dijitParams' => array(
146 $editorForm->addElement(
151 'inheritWidth' => 'true',
155 $toggleForm = new Zend_Dojo_Form_SubForm();
156 $toggleForm->setAttribs(array(
157 'name' => 'toggletab',
158 'legend' => 'Toggle Elements',
160 $toggleForm->addElement(
165 'label' => 'NumberSpinner',
168 'defaultTimeout' => 1000,
169 'timeoutChangeRate' => 100,
187 'label' => 'CheckBox',
188 'checkedValue' => 'foo',
189 'uncheckedValue' => 'bar',
197 'label' => 'RadioButton',
198 'multiOptions' => array(
206 $selectForm = new Zend_Dojo_Form_SubForm();
207 $selectForm->setAttribs(array(
208 'name' => 'selecttab',
209 'legend' => 'Select Elements',
211 $selectForm->addElement(
215 'label' => 'ComboBox (select)',
217 'autocomplete' => false,
218 'multiOptions' => $this->_selectOptions,
225 'label' => 'ComboBox (remoter)',
226 'storeId' => 'stateStore',
227 'storeType' => 'dojo.data.ItemFileReadStore',
228 'storeParams' => array(
229 'url' => '/js/states.txt',
231 'dijitParams' => array(
232 'searchAttr' => 'name',
240 'label' => 'FilteringSelect (select)',
242 'autocomplete' => false,
243 'multiOptions' => $this->_selectOptions,
248 'filterselectremote',
250 'label' => 'FilteringSelect (remoter)',
251 'storeId' => 'stateStore',
252 'storeType' => 'dojo.data.ItemFileReadStore',
253 'storeParams' => array(
254 'url' => '/js/states.txt',
256 'dijitParams' => array(
257 'searchAttr' => 'name',
261 $sliderForm = new Zend_Dojo_Form_SubForm();
262 $sliderForm->setAttribs(array(
263 'name' => 'slidertab',
264 'legend' => 'Slider Elements',
266 $sliderForm->addElement(
270 'label' => 'HorizontalSlider',
274 'discreteValues' => 11,
275 'intermediateChanges' => true,
276 'showButtons' => true,
277 'topDecorationDijit' => 'HorizontalRuleLabels',
278 'topDecorationContainer' => 'topContainer',
279 'topDecorationLabels' => array(
287 'topDecorationParams' => array(
288 'container' => array(
289 'style' => 'height:1.2em; ' .
290 'font-size=75%;color:gray;',
293 'style' => 'height:1em; ' .
294 'font-size=75%;color:gray;',
297 'bottomDecorationDijit' => 'HorizontalRule',
298 'bottomDecorationContainer' => 'bottomContainer',
299 'bottomDecorationLabels' => array(
304 'bottomDecorationParams' => array(
306 'style' => 'height:1em; ' .
307 'font-size=75%;color:gray;',
316 'label' => 'VerticalSlider',
318 'style' => 'height: 200px; width: 3em;',
321 'discreteValues' => 11,
322 'intermediateChanges' => true,
323 'showButtons' => true,
324 'leftDecorationDijit' => 'VerticalRuleLabels',
325 'leftDecorationContainer' => 'leftContainer',
326 'leftDecorationLabels' => array(
334 'rightDecorationDijit' => 'VerticalRule',
335 'rightDecorationContainer' => 'rightContainer',
336 'rightDecorationLabels' => array(
344 $this->addSubForm($textForm, 'textboxtab')
345 ->addSubForm($editorForm, 'editortab')
346 ->addSubForm($toggleForm, 'toggletab')
347 ->addSubForm($selectForm, 'selecttab')
348 ->addSubForm($sliderForm, 'slidertab');
354 <example id="zend.dojo.form.examples.decorating">
355 <title>Modifying an existing form to utilize Dojo</title>
358 Existing forms can be modified to utilize Dojo as well, by use of
359 the <methodname>Zend_Dojo::enableForm()</methodname> static method.
363 This first example shows decorating an existing form instance:
366 <programlisting language="php"><![CDATA[
367 $form = new My_Custom_Form();
368 Zend_Dojo::enableForm($form);
375 'autocomplete' => false,
376 'multiOptions' => array(
380 'orange' => 'Orange',
389 Alternately, you can make a slight tweak to your form
393 <programlisting language="php"><![CDATA[
394 class My_Custom_Form extends Zend_Form
396 public function init()
398 Zend_Dojo::enableForm($this);
406 Of course, if you can do that... you could and should simply alter
407 the class to inherit from <classname>Zend_Dojo_Form</classname>, which is a drop-in
408 replacement of <classname>Zend_Form</classname> that's already Dojo-enabled...