I have a form which uses a small amount of Dojo to swap option elements
between 2 multiselect boxes. It looks like this:

http://archive.dojotoolkit.org/nightly/dojotoolkit/dijit/tests/form/test_MultiSelect.html

and I've followed example code from here:

http://www.nabble.com/How-to-add-select%3Dselected-in-Zend_Form_Element_Multiselect-and-one-more-question-:)-td19166233.html

And everything works from the Dojo/Dijit point of view, except when I submit
my form, the 2 Multiselect boxes are not present in the POST data. I'm
pulling my hair out and can't think of an alternative way to implement this
interface. I'd be very grateful for any help. 

Here's my form

class Forms_Team_Manage extends Zend_Form { 

    public function __construct($options = null, $id = null) {
        parent::__construct($options);

        Zend_Dojo::enableForm($this);

        $this->setName('team_manage');
                $this->setAction("/team/manage/{$id}")
                     ->setMethod('post');

                $companyID = $this->createElement('hidden', 'Team_ID');
                
                $users = new Users;
                $allUsersData = $users->getUsersForOrganisationForForm($id);
                $allUsers = $this->createElement('multiselect', 'All_Users');
                $allUsers->setLabel('Users');
                $allUsers->setName('All_Users');
                $allUsers->setMultiOptions($allUsersData);
                $this->addElement($allUsers);
                
                $teams = new Teams;
                $teamUsersData = $teams->getTeam($id);
                $teamUsers = $this->createElement('multiselect', 
'Team_Members');
                $teamUsers->setLabel('Team Members');
                $teamUsers->setName('Team_Members');
                if (!empty($teamUsersData)) {
                        $teamUsers->setMultiOptions($teamUsersData);
                }
                $this->addElement($teamUsers);
                
                $this->addElement($companyID);
                
                //$this->addElement('submit', 'submit', array('label' => 'Add 
Team'));
                $this->addElement(
                    'SubmitButton',
                    'submit',
                    array(
                        'required'   => false,
                        'ignore'     => true,
                        'label'      => 'Update Team',
                    )
                );              


        foreach ($this->getSubForms() as $subForm) {
            Zend_Dojo::enableForm($subForm);
        }               
                
                
        }
}

and the view script:

<h1><?php echo $this->title; ?></h1>
<br />
<script type="text/javascript"> 
    dojo.require("dijit.dijit"); // optimize: load dijit layer
    dojo.require("dijit.form.MultiSelect");
    dojo.require("dijit.form.Button");

    dojo.addOnLoad(function(){

        // turn any non-dojoType selects into widgets programatically:
        dojo.query("select").forEach(function(n){
            if(!dijit.byNode(n)){
                var foo = new dijit.form.MultiSelect({ },n);
            }
        });

        // listen to the "move items" buttons
        dojo.query("button.switch").connect("onclick",function(e) {
            switch(e.target.id.toString()){
                case "addUser" : 
                   
dijit.byId("Team_Members").addSelected(dijit.byId("All_Users")); 
                    select.containerNode.appendChild(new
Option("text","value"));
                break;
                case "removeUser" : 
                   
dijit.byId("All_Users").addSelected(dijit.byId("Team_Members")); 
                    select.containerNode.appendChild(new
Option("text","value"));
                break;
            }
        });
    });
</script>

<?php echo $this->form; ?>

<button class="switch" id="addUser">Add >></button>

<button class="switch" id="removeUser"><< Remove</button>


<?php if (!empty($this->formError)) { ?>
    <script language="javascript" type="text/javascript">
        alert("<?php echo $this->formError; ?>"); 
    </script>
<?php } ?> 


And finally incase it's of use, the Action

        public function manageAction() {
                $this->view->title = 'Team Management';
                $id = $this->_getParam('id');
                
                $form = new Forms_Team_Manage(null, $id);
                $form->populate(array('Company_ID' => $id));

                if ($this->_request->isPost()) {
            $formData = $this->_request->getPost();
            if ($form->isValid($formData)) {
                $teams = new Teams;
                                print_r($formData);
                                //$id = $teams->addTeam($formData);
                                //$this->_redirect('/');
            } else {
                $form->populate($formData);
            }
        }

                $this->view->form = $form;
        }

-- 
View this message in context: 
http://www.nabble.com/MultiSelect-Zend_Form-item-not-available-in-POST-tp24586291p24586291.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to