| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- EN-Revision: 24249 -->
- <!-- Reviewed: no -->
- <sect2 id="zend.dojo.form.examples">
- <title>Ejemplos de Dojo Form</title>
- <example id="zend.dojo.form.examples.dojoform">
- <title>Usando Zend_Dojo_Form</title>
- <para>
- La forma más fácil de utilizar Dojo con
- <classname>Zend_Form</classname>
- es utilizar
- <classname>Zend_Dojo_Form</classname>
- , ya sea mediante el uso
- directo o mediante su extensión. Este ejemplo muestra la
- extensión
- de
- <classname>Zend_Dojo_Form</classname>
- , y muestra el uso de todos
- los elementos dijit. Crea cuatro sub forms, y decora el form
- para
- utilizar un TabContainer, mostrando cada sub form en su propia
- pestaña.
- </para>
- <programlisting language="php"><![CDATA[
- class My_Form_Test extends Zend_Dojo_Form
- {
- /**
- * Opciones para usar con elementos select
- */
- protected $_selectOptions = array(
- 'red' => 'Rouge',
- 'blue' => 'Bleu',
- 'white' => 'Blanc',
- 'orange' => 'Orange',
- 'black' => 'Noir',
- 'green' => 'Vert',
- );
- /**
- * Inicialización del Formn
- *
- * @return void
- */
- public function init()
- {
- $this->setMethod('post');
- $this->setAttribs(array(
- 'name' => 'masterForm',
- ));
- $this->setDecorators(array(
- 'FormElements',
- array('TabContainer', array(
- 'id' => 'tabContainer',
- 'style' => 'width: 600px; height: 500px;',
- 'dijitParams' => array(
- 'tabPosition' => 'top'
- ),
- )),
- 'DijitForm',
- ));
- $textForm = new Zend_Dojo_Form_SubForm();
- $textForm->setAttribs(array(
- 'name' => 'textboxtab',
- 'legend' => 'Text Elements',
- 'dijitParams' => array(
- 'title' => 'Text Elements',
- ),
- ));
- $textForm->addElement(
- 'TextBox',
- 'textbox',
- array(
- 'value' => 'some text',
- 'label' => 'TextBox',
- 'trim' => true,
- 'propercase' => true,
- )
- )
- ->addElement(
- 'DateTextBox',
- 'datebox',
- array(
- 'value' => '2008-07-05',
- 'label' => 'DateTextBox',
- 'required' => true,
- )
- )
- ->addElement(
- 'TimeTextBox',
- 'timebox',
- array(
- 'label' => 'TimeTextBox',
- 'required' => true,
- )
- )
- ->addElement(
- 'CurrencyTextBox',
- 'currencybox',
- array(
- 'label' => 'CurrencyTextBox',
- 'required' => true,
- // 'currency' => 'USD',
- 'invalidMessage' => 'Invalid amount. ' .
- 'Include dollar sign, commas, ' .
- 'and cents.',
- // 'fractional' => true,
- // 'symbol' => 'USD',
- // 'type' => 'currency',
- )
- )
- ->addElement(
- 'NumberTextBox',
- 'numberbox',
- array(
- 'label' => 'NumberTextBox',
- 'required' => true,
- 'invalidMessage' => 'Invalid elevation.',
- 'constraints' => array(
- 'min' => -20000,
- 'max' => 20000,
- 'places' => 0,
- )
- )
- )
- ->addElement(
- 'ValidationTextBox',
- 'validationbox',
- array(
- 'label' => 'ValidationTextBox',
- 'required' => true,
- 'regExp' => '[\w]+',
- 'invalidMessage' => 'Invalid non-space text.',
- )
- )
- ->addElement(
- 'Textarea',
- 'textarea',
- array(
- 'label' => 'Textarea',
- 'required' => true,
- 'style' => 'width: 200px;',
- )
- );
- $editorForm = new Zend_Dojo_Form_SubForm();
- $editorForm->setAttribs(array(
- 'name' => 'editortab',
- 'legend' => 'Editor',
- 'dijitParams' => array(
- 'title' => 'Editor'
- ),
- ))
- $editorForm->addElement(
- 'Editor',
- 'wysiwyg',
- array(
- 'label' => 'Editor',
- 'inheritWidth' => 'true',
- )
- );
- $toggleForm = new Zend_Dojo_Form_SubForm();
- $toggleForm->setAttribs(array(
- 'name' => 'toggletab',
- 'legend' => 'Toggle Elements',
- ));
- $toggleForm->addElement(
- 'NumberSpinner',
- 'ns',
- array(
- 'value' => '7',
- 'label' => 'NumberSpinner',
- 'smallDelta' => 5,
- 'largeDelta' => 25,
- 'defaultTimeout' => 1000,
- 'timeoutChangeRate' => 100,
- 'min' => 9,
- 'max' => 1550,
- 'places' => 0,
- 'maxlength' => 20,
- )
- )
- ->addElement(
- 'Button',
- 'dijitButton',
- array(
- 'label' => 'Button',
- )
- )
- ->addElement(
- 'CheckBox',
- 'checkbox',
- array(
- 'label' => 'CheckBox',
- 'checkedValue' => 'foo',
- 'uncheckedValue' => 'bar',
- 'checked' => true,
- )
- )
- ->addElement(
- 'RadioButton',
- 'radiobutton',
- array(
- 'label' => 'RadioButton',
- 'multiOptions' => array(
- 'foo' => 'Foo',
- 'bar' => 'Bar',
- 'baz' => 'Baz',
- ),
- 'value' => 'bar',
- )
- );
- $selectForm = new Zend_Dojo_Form_SubForm();
- $selectForm->setAttribs(array(
- 'name' => 'selecttab',
- 'legend' => 'Select Elements',
- ));
- $selectForm->addElement(
- 'ComboBox',
- 'comboboxselect',
- array(
- 'label' => 'ComboBox (select)',
- 'value' => 'blue',
- 'autocomplete' => false,
- 'multiOptions' => $this->_selectOptions,
- )
- )
- ->addElement(
- 'ComboBox',
- 'comboboxremote',
- array(
- 'label' => 'ComboBox (remoter)',
- 'storeId' => 'stateStore',
- 'storeType' => 'dojo.data.ItemFileReadStore',
- 'storeParams' => array(
- 'url' => '/js/states.txt',
- ),
- 'dijitParams' => array(
- 'searchAttr' => 'name',
- ),
- )
- )
- ->addElement(
- 'FilteringSelect',
- 'filterselect',
- array(
- 'label' => 'FilteringSelect (select)',
- 'value' => 'blue',
- 'autocomplete' => false,
- 'multiOptions' => $this->_selectOptions,
- )
- )
- ->addElement(
- 'FilteringSelect',
- 'filterselectremote',
- array(
- 'label' => 'FilteringSelect (remoter)',
- 'storeId' => 'stateStore',
- 'storeType' => 'dojo.data.ItemFileReadStore',
- 'storeParams' => array(
- 'url' => '/js/states.txt',
- ),
- 'dijitParams' => array(
- 'searchAttr' => 'name',
- ),
- )
- );
- $sliderForm = new Zend_Dojo_Form_SubForm();
- $sliderForm->setAttribs(array(
- 'name' => 'slidertab',
- 'legend' => 'Slider Elements',
- ));
- $sliderForm->addElement(
- 'HorizontalSlider',
- 'horizontal',
- array(
- 'label' => 'HorizontalSlider',
- 'value' => 5,
- 'minimum' => -10,
- 'maximum' => 10,
- 'discreteValues' => 11,
- 'intermediateChanges' => true,
- 'showButtons' => true,
- 'topDecorationDijit' => 'HorizontalRuleLabels',
- 'topDecorationContainer' => 'topContainer',
- 'topDecorationLabels' => array(
- ' ',
- '20%',
- '40%',
- '60%',
- '80%',
- ' ',
- ),
- 'topDecorationParams' => array(
- 'container' => array(
- 'style' => 'height:1.2em; ' .
- 'font-size=75%;color:gray;',
- ),
- 'list' => array(
- 'style' => 'height:1em; ' .
- 'font-size=75%;color:gray;',
- ),
- ),
- 'bottomDecorationDijit' => 'HorizontalRule',
- 'bottomDecorationContainer' => 'bottomContainer',
- 'bottomDecorationLabels' => array(
- '0%',
- '50%',
- '100%',
- ),
- 'bottomDecorationParams' => array(
- 'list' => array(
- 'style' => 'height:1em; ' .
- 'font-size=75%;color:gray;',
- ),
- ),
- )
- )
- ->addElement(
- 'VerticalSlider',
- 'vertical',
- array(
- 'label' => 'VerticalSlider',
- 'value' => 5,
- 'style' => 'height: 200px; width: 3em;',
- 'minimum' => -10,
- 'maximum' => 10,
- 'discreteValues' => 11,
- 'intermediateChanges' => true,
- 'showButtons' => true,
- 'leftDecorationDijit' => 'VerticalRuleLabels',
- 'leftDecorationContainer' => 'leftContainer',
- 'leftDecorationLabels' => array(
- ' ',
- '20%',
- '40%',
- '60%',
- '80%',
- ' ',
- ),
- 'rightDecorationDijit' => 'VerticalRule',
- 'rightDecorationContainer' => 'rightContainer',
- 'rightDecorationLabels' => array(
- '0%',
- '50%',
- '100%',
- ),
- )
- );
- $this->addSubForm($textForm, 'textboxtab')
- ->addSubForm($editorForm, 'editortab')
- ->addSubForm($toggleForm, 'toggletab')
- ->addSubForm($selectForm, 'selecttab')
- ->addSubForm($sliderForm, 'slidertab');
- }
- }
- ]]></programlisting>
- </example>
- <example id="zend.dojo.form.examples.decorating">
- <title>Modificando un form existente para utilizarlo con Dojo</title>
- <para>
- Los forms existentes pueden ser modificados para ser utilizados
- también por Dojo, usando
- el método estático
- <methodname>Zend_Dojo::enableForm()</methodname>
- .
- </para>
- <para>Este primer ejemplo muestra como decorar una instancia de un form
- existente:</para>
- <programlisting language="php"><![CDATA[
- $form = new My_Custom_Form();
- Zend_Dojo::enableForm($form);
- $form->addElement(
- 'ComboBox',
- 'query',
- array(
- 'label' => 'Color:',
- 'value' => 'blue',
- 'autocomplete' => false,
- 'multiOptions' => array(
- 'red' => 'Rouge',
- 'blue' => 'Bleu',
- 'white' => 'Blanc',
- 'orange' => 'Orange',
- 'black' => 'Noir',
- 'green' => 'Vert',
- ),
- )
- );
- ]]></programlisting>
- <para>Alternativamente, puede hacer un ligero retoque a su form de
- inicialización:</para>
- <programlisting language="php"><![CDATA[
- class My_Custom_Form extends Zend_Form
- {
- public function init()
- {
- Zend_Dojo::enableForm($this);
- // ...
- }
- }
- ]]></programlisting>
- <para>
- Por supuesto, si puede hacerlo... podría y debería simplemente
- alterar la clase a heredar
- de
- <classname>Zend_Dojo_Form</classname>
- ,
- que es una sustitución del drop-in de
- <classname>Zend_Form</classname>
- que ya está habilitada por
- Dojo....
- </para>
- </example>
- </sect2>
|