Zend_Dojo-Form.xml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.dojo.form" xmlns:xi="http://www.w3.org/2001/XInclude">
  4. <title>Dojo Form Elements and Decorators</title>
  5. <para>
  6. Building on the <link linkend="zend.dojo.view.dijit">dijit view
  7. helpers</link>, the <classname>Zend_Dojo_Form</classname> family of classes
  8. provides the ability to utilize Dijits natively within your forms.
  9. </para>
  10. <para>
  11. There are three options for utilizing the Dojo form elements with your
  12. forms:
  13. </para>
  14. <itemizedlist>
  15. <listitem>
  16. <para>
  17. Use <methodname>Zend_Dojo::enableForm()</methodname>. This will add plugin
  18. paths for decorators and elements to all attached form items,
  19. recursively. Additionally, it will dojo-enable the view object.
  20. Note, however, that any sub forms you attach
  21. <emphasis>after</emphasis> this call will also need to be
  22. passed through <methodname>Zend_Dojo::enableForm()</methodname>.
  23. </para>
  24. </listitem>
  25. <listitem>
  26. <para>
  27. Use the Dojo-specific form and subform implementations,
  28. <classname>Zend_Dojo_Form</classname> and
  29. <classname>Zend_Dojo_Form_SubForm</classname> respectively. These can be
  30. used as drop-in replacements for <classname>Zend_Form</classname> and
  31. <classname>Zend_Form_SubForm</classname>, contain all the appropriate
  32. decorator and element paths, set a Dojo-specific default
  33. DisplayGroup class, and dojo-enable the view.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. Last, and most tedious, you can set the appropriate decorator
  39. and element paths yourself, set the default DisplayGroup class,
  40. and dojo-enable the view. Since
  41. <methodname>Zend_Dojo::enableForm()</methodname> does this already, there's
  42. little reason to go this route.
  43. </para>
  44. </listitem>
  45. </itemizedlist>
  46. <example id="zend.dojo.form.enable">
  47. <title>Enabling Dojo in your existing forms</title>
  48. <para>
  49. "But wait," you say; "I'm already extending <classname>Zend_Form</classname> with my own
  50. custom form class! How can I Dojo-enable it?'"
  51. </para>
  52. <para>
  53. First, and easiest, simply change from extending
  54. <classname>Zend_Form</classname> to extending <classname>Zend_Dojo_Form</classname>,
  55. and update any places where you instantiate
  56. <classname>Zend_Form_SubForm</classname> to instantiate
  57. <classname>Zend_Dojo_Form_SubForm</classname>.
  58. </para>
  59. <para>
  60. A second approach is to call <methodname>Zend_Dojo::enableForm()</methodname>
  61. within your custom form's <methodname>init()</methodname> method; when the form
  62. definition is complete, loop through all SubForms to dojo-enable
  63. them:
  64. </para>
  65. <programlisting language="php"><![CDATA[
  66. class My_Form_Custom extends Zend_Form
  67. {
  68. public function init()
  69. {
  70. // Dojo-enable the form:
  71. Zend_Dojo::enableForm($this);
  72. // ... continue form definition from here
  73. // Dojo-enable all sub forms:
  74. foreach ($this->getSubForms() as $subForm) {
  75. Zend_Dojo::enableForm($subForm);
  76. }
  77. }
  78. }
  79. ]]></programlisting>
  80. </example>
  81. <para>
  82. Usage of the dijit-specific form decorators and elements is just like
  83. using any other form decorator or element.
  84. </para>
  85. <xi:include href="Zend_Dojo-Form-Decorators.xml" />
  86. <xi:include href="Zend_Dojo-Form-Elements.xml" />
  87. <xi:include href="Zend_Dojo-Form-Examples.xml" />
  88. </sect1>
  89. <!--
  90. vim:se ts=4 sw=4 et:
  91. -->