Zend_Dojo-Form-Examples.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 24249 -->
  3. <!-- Reviewed: no -->
  4. <sect2 id="zend.dojo.form.examples">
  5. <title>Ejemplos de Dojo Form</title>
  6. <example id="zend.dojo.form.examples.dojoform">
  7. <title>Usando Zend_Dojo_Form</title>
  8. <para>
  9. La forma más fácil de utilizar Dojo con
  10. <classname>Zend_Form</classname>
  11. es utilizar
  12. <classname>Zend_Dojo_Form</classname>
  13. , ya sea mediante el uso
  14. directo o mediante su extensión. Este ejemplo muestra la
  15. extensión
  16. de
  17. <classname>Zend_Dojo_Form</classname>
  18. , y muestra el uso de todos
  19. los elementos dijit. Crea cuatro sub forms, y decora el form
  20. para
  21. utilizar un TabContainer, mostrando cada sub form en su propia
  22. pestaña.
  23. </para>
  24. <programlisting language="php"><![CDATA[
  25. class My_Form_Test extends Zend_Dojo_Form
  26. {
  27. /**
  28. * Opciones para usar con elementos select
  29. */
  30. protected $_selectOptions = array(
  31. 'red' => 'Rouge',
  32. 'blue' => 'Bleu',
  33. 'white' => 'Blanc',
  34. 'orange' => 'Orange',
  35. 'black' => 'Noir',
  36. 'green' => 'Vert',
  37. );
  38. /**
  39. * Inicialización del Formn
  40. *
  41. * @return void
  42. */
  43. public function init()
  44. {
  45. $this->setMethod('post');
  46. $this->setAttribs(array(
  47. 'name' => 'masterForm',
  48. ));
  49. $this->setDecorators(array(
  50. 'FormElements',
  51. array('TabContainer', array(
  52. 'id' => 'tabContainer',
  53. 'style' => 'width: 600px; height: 500px;',
  54. 'dijitParams' => array(
  55. 'tabPosition' => 'top'
  56. ),
  57. )),
  58. 'DijitForm',
  59. ));
  60. $textForm = new Zend_Dojo_Form_SubForm();
  61. $textForm->setAttribs(array(
  62. 'name' => 'textboxtab',
  63. 'legend' => 'Text Elements',
  64. 'dijitParams' => array(
  65. 'title' => 'Text Elements',
  66. ),
  67. ));
  68. $textForm->addElement(
  69. 'TextBox',
  70. 'textbox',
  71. array(
  72. 'value' => 'some text',
  73. 'label' => 'TextBox',
  74. 'trim' => true,
  75. 'propercase' => true,
  76. )
  77. )
  78. ->addElement(
  79. 'DateTextBox',
  80. 'datebox',
  81. array(
  82. 'value' => '2008-07-05',
  83. 'label' => 'DateTextBox',
  84. 'required' => true,
  85. )
  86. )
  87. ->addElement(
  88. 'TimeTextBox',
  89. 'timebox',
  90. array(
  91. 'label' => 'TimeTextBox',
  92. 'required' => true,
  93. )
  94. )
  95. ->addElement(
  96. 'CurrencyTextBox',
  97. 'currencybox',
  98. array(
  99. 'label' => 'CurrencyTextBox',
  100. 'required' => true,
  101. // 'currency' => 'USD',
  102. 'invalidMessage' => 'Invalid amount. ' .
  103. 'Include dollar sign, commas, ' .
  104. 'and cents.',
  105. // 'fractional' => true,
  106. // 'symbol' => 'USD',
  107. // 'type' => 'currency',
  108. )
  109. )
  110. ->addElement(
  111. 'NumberTextBox',
  112. 'numberbox',
  113. array(
  114. 'label' => 'NumberTextBox',
  115. 'required' => true,
  116. 'invalidMessage' => 'Invalid elevation.',
  117. 'constraints' => array(
  118. 'min' => -20000,
  119. 'max' => 20000,
  120. 'places' => 0,
  121. )
  122. )
  123. )
  124. ->addElement(
  125. 'ValidationTextBox',
  126. 'validationbox',
  127. array(
  128. 'label' => 'ValidationTextBox',
  129. 'required' => true,
  130. 'regExp' => '[\w]+',
  131. 'invalidMessage' => 'Invalid non-space text.',
  132. )
  133. )
  134. ->addElement(
  135. 'Textarea',
  136. 'textarea',
  137. array(
  138. 'label' => 'Textarea',
  139. 'required' => true,
  140. 'style' => 'width: 200px;',
  141. )
  142. );
  143. $editorForm = new Zend_Dojo_Form_SubForm();
  144. $editorForm->setAttribs(array(
  145. 'name' => 'editortab',
  146. 'legend' => 'Editor',
  147. 'dijitParams' => array(
  148. 'title' => 'Editor'
  149. ),
  150. ))
  151. $editorForm->addElement(
  152. 'Editor',
  153. 'wysiwyg',
  154. array(
  155. 'label' => 'Editor',
  156. 'inheritWidth' => 'true',
  157. )
  158. );
  159. $toggleForm = new Zend_Dojo_Form_SubForm();
  160. $toggleForm->setAttribs(array(
  161. 'name' => 'toggletab',
  162. 'legend' => 'Toggle Elements',
  163. ));
  164. $toggleForm->addElement(
  165. 'NumberSpinner',
  166. 'ns',
  167. array(
  168. 'value' => '7',
  169. 'label' => 'NumberSpinner',
  170. 'smallDelta' => 5,
  171. 'largeDelta' => 25,
  172. 'defaultTimeout' => 1000,
  173. 'timeoutChangeRate' => 100,
  174. 'min' => 9,
  175. 'max' => 1550,
  176. 'places' => 0,
  177. 'maxlength' => 20,
  178. )
  179. )
  180. ->addElement(
  181. 'Button',
  182. 'dijitButton',
  183. array(
  184. 'label' => 'Button',
  185. )
  186. )
  187. ->addElement(
  188. 'CheckBox',
  189. 'checkbox',
  190. array(
  191. 'label' => 'CheckBox',
  192. 'checkedValue' => 'foo',
  193. 'uncheckedValue' => 'bar',
  194. 'checked' => true,
  195. )
  196. )
  197. ->addElement(
  198. 'RadioButton',
  199. 'radiobutton',
  200. array(
  201. 'label' => 'RadioButton',
  202. 'multiOptions' => array(
  203. 'foo' => 'Foo',
  204. 'bar' => 'Bar',
  205. 'baz' => 'Baz',
  206. ),
  207. 'value' => 'bar',
  208. )
  209. );
  210. $selectForm = new Zend_Dojo_Form_SubForm();
  211. $selectForm->setAttribs(array(
  212. 'name' => 'selecttab',
  213. 'legend' => 'Select Elements',
  214. ));
  215. $selectForm->addElement(
  216. 'ComboBox',
  217. 'comboboxselect',
  218. array(
  219. 'label' => 'ComboBox (select)',
  220. 'value' => 'blue',
  221. 'autocomplete' => false,
  222. 'multiOptions' => $this->_selectOptions,
  223. )
  224. )
  225. ->addElement(
  226. 'ComboBox',
  227. 'comboboxremote',
  228. array(
  229. 'label' => 'ComboBox (remoter)',
  230. 'storeId' => 'stateStore',
  231. 'storeType' => 'dojo.data.ItemFileReadStore',
  232. 'storeParams' => array(
  233. 'url' => '/js/states.txt',
  234. ),
  235. 'dijitParams' => array(
  236. 'searchAttr' => 'name',
  237. ),
  238. )
  239. )
  240. ->addElement(
  241. 'FilteringSelect',
  242. 'filterselect',
  243. array(
  244. 'label' => 'FilteringSelect (select)',
  245. 'value' => 'blue',
  246. 'autocomplete' => false,
  247. 'multiOptions' => $this->_selectOptions,
  248. )
  249. )
  250. ->addElement(
  251. 'FilteringSelect',
  252. 'filterselectremote',
  253. array(
  254. 'label' => 'FilteringSelect (remoter)',
  255. 'storeId' => 'stateStore',
  256. 'storeType' => 'dojo.data.ItemFileReadStore',
  257. 'storeParams' => array(
  258. 'url' => '/js/states.txt',
  259. ),
  260. 'dijitParams' => array(
  261. 'searchAttr' => 'name',
  262. ),
  263. )
  264. );
  265. $sliderForm = new Zend_Dojo_Form_SubForm();
  266. $sliderForm->setAttribs(array(
  267. 'name' => 'slidertab',
  268. 'legend' => 'Slider Elements',
  269. ));
  270. $sliderForm->addElement(
  271. 'HorizontalSlider',
  272. 'horizontal',
  273. array(
  274. 'label' => 'HorizontalSlider',
  275. 'value' => 5,
  276. 'minimum' => -10,
  277. 'maximum' => 10,
  278. 'discreteValues' => 11,
  279. 'intermediateChanges' => true,
  280. 'showButtons' => true,
  281. 'topDecorationDijit' => 'HorizontalRuleLabels',
  282. 'topDecorationContainer' => 'topContainer',
  283. 'topDecorationLabels' => array(
  284. ' ',
  285. '20%',
  286. '40%',
  287. '60%',
  288. '80%',
  289. ' ',
  290. ),
  291. 'topDecorationParams' => array(
  292. 'container' => array(
  293. 'style' => 'height:1.2em; ' .
  294. 'font-size=75%;color:gray;',
  295. ),
  296. 'list' => array(
  297. 'style' => 'height:1em; ' .
  298. 'font-size=75%;color:gray;',
  299. ),
  300. ),
  301. 'bottomDecorationDijit' => 'HorizontalRule',
  302. 'bottomDecorationContainer' => 'bottomContainer',
  303. 'bottomDecorationLabels' => array(
  304. '0%',
  305. '50%',
  306. '100%',
  307. ),
  308. 'bottomDecorationParams' => array(
  309. 'list' => array(
  310. 'style' => 'height:1em; ' .
  311. 'font-size=75%;color:gray;',
  312. ),
  313. ),
  314. )
  315. )
  316. ->addElement(
  317. 'VerticalSlider',
  318. 'vertical',
  319. array(
  320. 'label' => 'VerticalSlider',
  321. 'value' => 5,
  322. 'style' => 'height: 200px; width: 3em;',
  323. 'minimum' => -10,
  324. 'maximum' => 10,
  325. 'discreteValues' => 11,
  326. 'intermediateChanges' => true,
  327. 'showButtons' => true,
  328. 'leftDecorationDijit' => 'VerticalRuleLabels',
  329. 'leftDecorationContainer' => 'leftContainer',
  330. 'leftDecorationLabels' => array(
  331. ' ',
  332. '20%',
  333. '40%',
  334. '60%',
  335. '80%',
  336. ' ',
  337. ),
  338. 'rightDecorationDijit' => 'VerticalRule',
  339. 'rightDecorationContainer' => 'rightContainer',
  340. 'rightDecorationLabels' => array(
  341. '0%',
  342. '50%',
  343. '100%',
  344. ),
  345. )
  346. );
  347. $this->addSubForm($textForm, 'textboxtab')
  348. ->addSubForm($editorForm, 'editortab')
  349. ->addSubForm($toggleForm, 'toggletab')
  350. ->addSubForm($selectForm, 'selecttab')
  351. ->addSubForm($sliderForm, 'slidertab');
  352. }
  353. }
  354. ]]></programlisting>
  355. </example>
  356. <example id="zend.dojo.form.examples.decorating">
  357. <title>Modificando un form existente para utilizarlo con Dojo</title>
  358. <para>
  359. Los forms existentes pueden ser modificados para ser utilizados
  360. también por Dojo, usando
  361. el método estático
  362. <methodname>Zend_Dojo::enableForm()</methodname>
  363. .
  364. </para>
  365. <para>Este primer ejemplo muestra como decorar una instancia de un form
  366. existente:</para>
  367. <programlisting language="php"><![CDATA[
  368. $form = new My_Custom_Form();
  369. Zend_Dojo::enableForm($form);
  370. $form->addElement(
  371. 'ComboBox',
  372. 'query',
  373. array(
  374. 'label' => 'Color:',
  375. 'value' => 'blue',
  376. 'autocomplete' => false,
  377. 'multiOptions' => array(
  378. 'red' => 'Rouge',
  379. 'blue' => 'Bleu',
  380. 'white' => 'Blanc',
  381. 'orange' => 'Orange',
  382. 'black' => 'Noir',
  383. 'green' => 'Vert',
  384. ),
  385. )
  386. );
  387. ]]></programlisting>
  388. <para>Alternativamente, puede hacer un ligero retoque a su form de
  389. inicialización:</para>
  390. <programlisting language="php"><![CDATA[
  391. class My_Custom_Form extends Zend_Form
  392. {
  393. public function init()
  394. {
  395. Zend_Dojo::enableForm($this);
  396. // ...
  397. }
  398. }
  399. ]]></programlisting>
  400. <para>
  401. Por supuesto, si puede hacerlo... podría y debería simplemente
  402. alterar la clase a heredar
  403. de
  404. <classname>Zend_Dojo_Form</classname>
  405. ,
  406. que es una sustitución del drop-in de
  407. <classname>Zend_Form</classname>
  408. que ya está habilitada por
  409. Dojo....
  410. </para>
  411. </example>
  412. </sect2>