Zend_Dojo-Form-Examples.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 24249 -->
  4. <sect2 id="zend.dojo.form.examples">
  5. <title>Dojo Formサンプル</title>
  6. <example id="zend.dojo.form.examples.dojoform">
  7. <title>Zend_Dojo_Formの利用</title>
  8. <para>
  9. 直接使うにせよ、それを拡張するにせよ、
  10. <classname>Zend_Form</classname>でDojoを利用する最も簡単な方法は、
  11. <classname>Zend_Dojo_Form</classname>を利用することです。
  12. この例では<classname>Zend_Dojo_Form</classname>の拡張と、
  13. すべてのdijit要素の使用法を示します。
  14. それは4つのサブ・フォームをつくって、TabContainerを利用するためにフォームを飾ります。
  15. そして、それ自身のタブの中に各々のサブ・フォームを表示します。
  16. </para>
  17. <programlisting language="php"><![CDATA[
  18. class My_Form_Test extends Zend_Dojo_Form
  19. {
  20. /**
  21. * select要素で使う選択肢
  22. */
  23. protected $_selectOptions = array(
  24. 'red' => 'Rouge',
  25. 'blue' => 'Bleu',
  26. 'white' => 'Blanc',
  27. 'orange' => 'Orange',
  28. 'black' => 'Noir',
  29. 'green' => 'Vert',
  30. );
  31. /**
  32. * Form初期化
  33. *
  34. * @return void
  35. */
  36. public function init()
  37. {
  38. $this->setMethod('post');
  39. $this->setAttribs(array(
  40. 'name' => 'masterForm',
  41. ));
  42. $this->setDecorators(array(
  43. 'FormElements',
  44. array('TabContainer', array(
  45. 'id' => 'tabContainer',
  46. 'style' => 'width: 600px; height: 500px;',
  47. 'dijitParams' => array(
  48. 'tabPosition' => 'top'
  49. ),
  50. )),
  51. 'DijitForm',
  52. ));
  53. $textForm = new Zend_Dojo_Form_SubForm();
  54. $textForm->setAttribs(array(
  55. 'name' => 'textboxtab',
  56. 'legend' => 'Text Elements',
  57. 'dijitParams' => array(
  58. 'title' => 'Text Elements',
  59. ),
  60. ));
  61. $textForm->addElement(
  62. 'TextBox',
  63. 'textbox',
  64. array(
  65. 'value' => 'some text',
  66. 'label' => 'TextBox',
  67. 'trim' => true,
  68. 'propercase' => true,
  69. )
  70. )
  71. ->addElement(
  72. 'DateTextBox',
  73. 'datebox',
  74. array(
  75. 'value' => '2008-07-05',
  76. 'label' => 'DateTextBox',
  77. 'required' => true,
  78. )
  79. )
  80. ->addElement(
  81. 'TimeTextBox',
  82. 'timebox',
  83. array(
  84. 'label' => 'TimeTextBox',
  85. 'required' => true,
  86. )
  87. )
  88. ->addElement(
  89. 'CurrencyTextBox',
  90. 'currencybox',
  91. array(
  92. 'label' => 'CurrencyTextBox',
  93. 'required' => true,
  94. // 'currency' => 'USD',
  95. 'invalidMessage' => 'Invalid amount. ' .
  96. 'Include dollar sign, commas, ' .
  97. 'and cents.',
  98. // 'fractional' => true,
  99. // 'symbol' => 'USD',
  100. // 'type' => 'currency',
  101. )
  102. )
  103. ->addElement(
  104. 'NumberTextBox',
  105. 'numberbox',
  106. array(
  107. 'label' => 'NumberTextBox',
  108. 'required' => true,
  109. 'invalidMessage' => 'Invalid elevation.',
  110. 'constraints' => array(
  111. 'min' => -20000,
  112. 'max' => 20000,
  113. 'places' => 0,
  114. )
  115. )
  116. )
  117. ->addElement(
  118. 'ValidationTextBox',
  119. 'validationbox',
  120. array(
  121. 'label' => 'ValidationTextBox',
  122. 'required' => true,
  123. 'regExp' => '[\w]+',
  124. 'invalidMessage' => 'Invalid non-space text.',
  125. )
  126. )
  127. ->addElement(
  128. 'Textarea',
  129. 'textarea',
  130. array(
  131. 'label' => 'Textarea',
  132. 'required' => true,
  133. 'style' => 'width: 200px;',
  134. )
  135. );
  136. $editorForm = new Zend_Dojo_Form_SubForm();
  137. $editorForm->setAttribs(array(
  138. 'name' => 'editortab',
  139. 'legend' => 'Editor',
  140. 'dijitParams' => array(
  141. 'title' => 'Editor'
  142. ),
  143. ))
  144. $editorForm->addElement(
  145. 'Editor',
  146. 'wysiwyg',
  147. array(
  148. 'label' => 'Editor',
  149. 'inheritWidth' => 'true',
  150. )
  151. );
  152. $toggleForm = new Zend_Dojo_Form_SubForm();
  153. $toggleForm->setAttribs(array(
  154. 'name' => 'toggletab',
  155. 'legend' => 'Toggle Elements',
  156. ));
  157. $toggleForm->addElement(
  158. 'NumberSpinner',
  159. 'ns',
  160. array(
  161. 'value' => '7',
  162. 'label' => 'NumberSpinner',
  163. 'smallDelta' => 5,
  164. 'largeDelta' => 25,
  165. 'defaultTimeout' => 1000,
  166. 'timeoutChangeRate' => 100,
  167. 'min' => 9,
  168. 'max' => 1550,
  169. 'places' => 0,
  170. 'maxlength' => 20,
  171. )
  172. )
  173. ->addElement(
  174. 'Button',
  175. 'dijitButton',
  176. array(
  177. 'label' => 'Button',
  178. )
  179. )
  180. ->addElement(
  181. 'CheckBox',
  182. 'checkbox',
  183. array(
  184. 'label' => 'CheckBox',
  185. 'checkedValue' => 'foo',
  186. 'uncheckedValue' => 'bar',
  187. 'checked' => true,
  188. )
  189. )
  190. ->addElement(
  191. 'RadioButton',
  192. 'radiobutton',
  193. array(
  194. 'label' => 'RadioButton',
  195. 'multiOptions' => array(
  196. 'foo' => 'Foo',
  197. 'bar' => 'Bar',
  198. 'baz' => 'Baz',
  199. ),
  200. 'value' => 'bar',
  201. )
  202. );
  203. $selectForm = new Zend_Dojo_Form_SubForm();
  204. $selectForm->setAttribs(array(
  205. 'name' => 'selecttab',
  206. 'legend' => 'Select Elements',
  207. ));
  208. $selectForm->addElement(
  209. 'ComboBox',
  210. 'comboboxselect',
  211. array(
  212. 'label' => 'ComboBox (select)',
  213. 'value' => 'blue',
  214. 'autocomplete' => false,
  215. 'multiOptions' => $this->_selectOptions,
  216. )
  217. )
  218. ->addElement(
  219. 'ComboBox',
  220. 'comboboxremote',
  221. array(
  222. 'label' => 'ComboBox (remoter)',
  223. 'storeId' => 'stateStore',
  224. 'storeType' => 'dojo.data.ItemFileReadStore',
  225. 'storeParams' => array(
  226. 'url' => '/js/states.txt',
  227. ),
  228. 'dijitParams' => array(
  229. 'searchAttr' => 'name',
  230. ),
  231. )
  232. )
  233. ->addElement(
  234. 'FilteringSelect',
  235. 'filterselect',
  236. array(
  237. 'label' => 'FilteringSelect (select)',
  238. 'value' => 'blue',
  239. 'autocomplete' => false,
  240. 'multiOptions' => $this->_selectOptions,
  241. )
  242. )
  243. ->addElement(
  244. 'FilteringSelect',
  245. 'filterselectremote',
  246. array(
  247. 'label' => 'FilteringSelect (remoter)',
  248. 'storeId' => 'stateStore',
  249. 'storeType' => 'dojo.data.ItemFileReadStore',
  250. 'storeParams' => array(
  251. 'url' => '/js/states.txt',
  252. ),
  253. 'dijitParams' => array(
  254. 'searchAttr' => 'name',
  255. ),
  256. )
  257. );
  258. $sliderForm = new Zend_Dojo_Form_SubForm();
  259. $sliderForm->setAttribs(array(
  260. 'name' => 'slidertab',
  261. 'legend' => 'Slider Elements',
  262. ));
  263. $sliderForm->addElement(
  264. 'HorizontalSlider',
  265. 'horizontal',
  266. array(
  267. 'label' => 'HorizontalSlider',
  268. 'value' => 5,
  269. 'minimum' => -10,
  270. 'maximum' => 10,
  271. 'discreteValues' => 11,
  272. 'intermediateChanges' => true,
  273. 'showButtons' => true,
  274. 'topDecorationDijit' => 'HorizontalRuleLabels',
  275. 'topDecorationContainer' => 'topContainer',
  276. 'topDecorationLabels' => array(
  277. ' ',
  278. '20%',
  279. '40%',
  280. '60%',
  281. '80%',
  282. ' ',
  283. ),
  284. 'topDecorationParams' => array(
  285. 'container' => array(
  286. 'style' => 'height:1.2em; ' .
  287. 'font-size=75%;color:gray;',
  288. ),
  289. 'list' => array(
  290. 'style' => 'height:1em; ' .
  291. 'font-size=75%;color:gray;',
  292. ),
  293. ),
  294. 'bottomDecorationDijit' => 'HorizontalRule',
  295. 'bottomDecorationContainer' => 'bottomContainer',
  296. 'bottomDecorationLabels' => array(
  297. '0%',
  298. '50%',
  299. '100%',
  300. ),
  301. 'bottomDecorationParams' => array(
  302. 'list' => array(
  303. 'style' => 'height:1em; ' .
  304. 'font-size=75%;color:gray;',
  305. ),
  306. ),
  307. )
  308. )
  309. ->addElement(
  310. 'VerticalSlider',
  311. 'vertical',
  312. array(
  313. 'label' => 'VerticalSlider',
  314. 'value' => 5,
  315. 'style' => 'height: 200px; width: 3em;',
  316. 'minimum' => -10,
  317. 'maximum' => 10,
  318. 'discreteValues' => 11,
  319. 'intermediateChanges' => true,
  320. 'showButtons' => true,
  321. 'leftDecorationDijit' => 'VerticalRuleLabels',
  322. 'leftDecorationContainer' => 'leftContainer',
  323. 'leftDecorationLabels' => array(
  324. ' ',
  325. '20%',
  326. '40%',
  327. '60%',
  328. '80%',
  329. ' ',
  330. ),
  331. 'rightDecorationDijit' => 'VerticalRule',
  332. 'rightDecorationContainer' => 'rightContainer',
  333. 'rightDecorationLabels' => array(
  334. '0%',
  335. '50%',
  336. '100%',
  337. ),
  338. )
  339. );
  340. $this->addSubForm($textForm, 'textboxtab')
  341. ->addSubForm($editorForm, 'editortab')
  342. ->addSubForm($toggleForm, 'toggletab')
  343. ->addSubForm($selectForm, 'selecttab')
  344. ->addSubForm($sliderForm, 'slidertab');
  345. }
  346. }
  347. ]]></programlisting>
  348. </example>
  349. <example id="zend.dojo.form.examples.decorating">
  350. <title>既存のフォームをDojoを使って変更する</title>
  351. <para>
  352. <methodname>Zend_Dojo::enableForm()</methodname>という静的メソッドを利用して、
  353. 既存のフォームをDojoを使って変更することもできます。
  354. </para>
  355. <para>
  356. 最初の例では既存のフォームの例を修飾して見せています。
  357. </para>
  358. <programlisting language="php"><![CDATA[
  359. $form = new My_Custom_Form();
  360. Zend_Dojo::enableForm($form);
  361. $form->addElement(
  362. 'ComboBox',
  363. 'query',
  364. array(
  365. 'label' => 'Color:',
  366. 'value' => 'blue',
  367. 'autocomplete' => false,
  368. 'multiOptions' => array(
  369. 'red' => 'Rouge',
  370. 'blue' => 'Bleu',
  371. 'white' => 'Blanc',
  372. 'orange' => 'Orange',
  373. 'black' => 'Noir',
  374. 'green' => 'Vert',
  375. ),
  376. )
  377. );
  378. ]]></programlisting>
  379. <para>
  380. あるいは、フォームの初期化でわずかな微調整をすることができます:
  381. </para>
  382. <programlisting language="php"><![CDATA[
  383. class My_Custom_Form extends Zend_Form
  384. {
  385. public function init()
  386. {
  387. Zend_Dojo::enableForm($this);
  388. // ...
  389. }
  390. }
  391. ]]></programlisting>
  392. <para>
  393. もちろん、可能ならば、<classname>Zend_Dojo_Form</classname>を継承したクラスで単純に置き換えられるか、
  394. 置き換えたいでしょう。
  395. そのクラスはすでにDojoが有効の<classname>Zend_Form</classname>の選択リストの代わりです。
  396. </para>
  397. </example>
  398. </sect2>
  399. <!--
  400. vim:se ts=4 sw=4 et:
  401. -->