Ver Mensaje Individual
  #6 (permalink)  
Antiguo 24/09/2011, 17:15
Avatar de abimaelrc
abimaelrc
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: En el planeta de Puerto Rico
Mensajes: 14.734
Antigüedad: 14 años, 11 meses
Puntos: 1517
Respuesta: Zend Variable

Pues lo que te indicó GatorV es correcto. Con JS lo puedes hacer, solo tienes que indicar en el formulario que el segundo campo tenga setRegisterInArrayValidator(false) para que zend no interprete los valores que tiene ya que si no te dará un mensaje de que el valor escogido no está en el haytack. Algo así debes tener en el zend_form

/application/forms/Form.php
Código PHP:
Ver original
  1. <?php
  2. class Application_Form_Form extends Zend_Form
  3. {
  4.     public function init()
  5.     {
  6.         $this->setDecorators(
  7.                 array(
  8.                     'FormElements',
  9.                     'Form',
  10.                 )
  11.             );
  12.  
  13.         $foo = new Zend_Form_Element_Select('foo');
  14.         $foo->setLabel('Foo:')
  15.             ->setDecorators(
  16.                 array(
  17.                     'Errors',
  18.                     array('Label', array('placement' => 'append')),
  19.                     'ViewHelper',
  20.                     array('HtmlTag', array('tag'=>'div')),
  21.                 )
  22.             )
  23.             ->setRequired(true)
  24.             ->addMultiOptions(
  25.                 array(
  26.                     '' => '[Foo]',
  27.                     'foo' => 'Foo',
  28.                     'bar' => 'Bar',
  29.                     'candy' => 'Candy'
  30.                 )
  31.             );
  32.  
  33.         $bar = new Zend_Form_Element_Select('bar');
  34.         $bar->setLabel('Bar:')
  35.             ->setDecorators(
  36.                 array(
  37.                     'Errors',
  38.                     array('Label', array('placement' => 'append')),
  39.                     'ViewHelper',
  40.                     array('HtmlTag', array('tag'=>'div')),
  41.                 )
  42.             )
  43.             ->setRequired(true)
  44.             ->setRegisterInArrayValidator(false)
  45.             ->addMultiOptions(
  46.                 array(
  47.                     '' => '[Foo]'
  48.                 )
  49.             );
  50.  
  51.         $submit = new Zend_Form_Element_Submit('submit');
  52.         $submit->setLabel('Add Tour')
  53.             ->setOptions(array('class' => 'submit'))
  54.             ->setDecorators(
  55.                 array(
  56.                     array('ViewHelper'),
  57.                     array('HtmlTag', array('tag' => 'div')),
  58.                 )
  59.             );
  60.  
  61.         // attach elements to form
  62.         $this->addElements(
  63.             array(
  64.                 $foo,
  65.                 $bar,
  66.                 $submit,
  67.             )
  68.         );
  69.     }
  70. }

/application/controllers/IndexController.php
Código PHP:
Ver original
  1. <?php
  2. class IndexController extends Zend_Controller_Action
  3. {
  4.  
  5.     public function init()
  6.     {
  7.        
  8.     }
  9.  
  10.     public function indexAction()
  11.     {
  12.         $form = new Application_Form_Form();
  13.         $form->setAction('/')
  14.             ->setMethod('post');
  15.         $this->view->form = $form;
  16.  
  17.         if($this->getRequest()->isPost()){
  18.             if($form->isValid($this->getRequest()->getPost())){
  19.                
  20.             }
  21.         }
  22.     }
  23. }

/application/views/scripts/index.phtml
Código PHP:
Ver original
  1. <?php
  2. $this->headScript()
  3.     ->appendScript('var arrOpt = new Array();
  4. arrOpt["foo"] = new Array();
  5. arrOpt["foo"]["1_foo1"] = new Array();
  6. arrOpt["foo"]["2_foo2"] = new Array();
  7. arrOpt["foo"]["3_foo3"] = new Array();
  8.  
  9. arrOpt["bar"] = new Array();
  10. arrOpt["bar"]["1_bar3"] = new Array();
  11. arrOpt["bar"]["2_bar2"] = new Array();
  12. arrOpt["bar"]["3_bar3"] = new Array();
  13.  
  14. arrOpt["candy"] = new Array();
  15. arrOpt["candy"]["1_candy1"] = new Array();
  16. arrOpt["candy"]["2_candy2"] = new Array();
  17. arrOpt["candy"]["3_candy3"] = new Array();
  18.  
  19. var fIndexSession = 0;
  20. var sIndexSession = 0;
  21. function addEvent(obj,type,fun){  
  22.     if(obj.addEventListener){  
  23.         obj.addEventListener(type,fun,false);  
  24.     }else if(obj.attachEvent){  
  25.         var f=function(){  
  26.             fun.call(obj,window.event);  
  27.         }  
  28.         obj.attachEvent("on"+type,f);  
  29.         obj[fun.toString()+type]=f;  
  30.     }else{  
  31.         obj["on"+type]=fun;  
  32.     }  
  33. }
  34. function nullOptions(obj){
  35.     var n=obj.options.length
  36.     for (i=0;i<n;i++){
  37.         obj.options[i]=null
  38.     }
  39.     obj.options.length=0;
  40. }
  41.  
  42. window.onload = function(){
  43.     addEvent(document.getElementById("foo"), "change", function(){
  44.         var f = this;
  45.         var fIndex = f.selectedIndex;
  46.  
  47.         var s = document.getElementById("bar");
  48.         var sIndex = fIndexSession == fIndex ? s.selectedIndex : 0;
  49.         nullOptions(s);
  50.         sText = fIndex > 0
  51.             ? "Bar"
  52.             : "Foo";
  53.         s.options[0] = new Option("[" + sText + "]", "", true);
  54.  
  55.         fIndexSession = fIndex;
  56.         sIndexSession = sIndex;
  57.  
  58.         for(var i in arrOpt){
  59.             if(i == f.value){
  60.                 var n = 1;
  61.                 for(var ii in arrOpt[i]){
  62.                     sKey = ii.split("_");
  63.                     bool = sIndex == n ? true : false;
  64.                     s.options[n++] = new Option(sKey[1], sKey[0], false, bool);
  65.                 }
  66.             }
  67.         }
  68.     });
  69. }');
  70. echo $this->headScript();
  71. echo $this->form;
  72. ?>
__________________
Verifica antes de preguntar.
Los verdaderos amigos se hieren con la verdad, para no perderlos con la mentira. - Eugenio Maria de Hostos