DooPHP IRC channel


Select Multiple

Discussion about new desired features.

Select Multiple

Postby chucka » Thu Dec 17, 2009 10:26 pm

Looking into building some multiselect boxes with DooForm but am finding its missing the ability to mark options as selected on creation. Am I correct? If I am I'd like to request this addition. Here is my field from my form:

Code: Select all
            'components' => array('select', array(
               'required' => false,
               'attributes' => array('multiple'=>'mulitple'),
               'multioptions' => $this->data['components'],
               'wrapper' => 'div',
               'label' => 'Components in Category:'
            )),
Image
chucka
 
Posts: 101
Joined: Tue Oct 06, 2009 7:39 pm

Re: Select Multiple

Postby chucka » Mon Dec 28, 2009 2:44 pm

Maybe I didn't explain this well enough. I'd like to make a dooForm which contains multiple select box.

Example:
Code: Select all
<select multiple="multiple">
<option value="48">Item 1</option>
<option value="32">Item 2</option>
<option value="19" selected="selected">Item 3</option>
<option value="3" selected="selected">Item 4</option>
<option value="59">Item 5</option>
<option value="46">Item 6</option>
<option value="27" selected="selected">Item 7</option>
</select>


Can this be done? I'm looking to use it with this: http://www.quasipartikel.at/multiselect/index.html
Image
chucka
 
Posts: 101
Joined: Tue Oct 06, 2009 7:39 pm

Re: Select Multiple

Postby chucka » Mon Dec 28, 2009 7:14 pm

To make this work and be compatible the creation style for the other Multi optioned form inputs I've thrown this code together and would like to contribute it to DooForm.php. What do my fellow Doo'ers think?

Code: Select all
            //MultiSelect, a hybrid of select and MultiCheckbox for mulitple select lists
            case 'MultiSelect':
               $elementHtml = '<'.$elementWrapper.' id="'.$element.'-element" '.$elementRequred.'><select '.$elementAttributes.' multiple="multiple" name="'.$element.'[]">';
               if (isset($k[1]['multioptions']) && (count($k[1]['multioptions'] > 0))) {
                  foreach ($k[1]['multioptions'] as $optionValue => $optionName) {
                     if (is_array($optionName)) { // if its array make option groups
                        $elementHtml .= '<optgroup label="'.$optionValue.'">';
                        foreach ($optionName as $v => $n) {
                           $selected = (isset($k[1]['value']) && (in_array($v, $k[1]['value'])))?'selected="selected"':'';
                           $elementHtml .= '<option value="'.$v.'" '.$selected.'>'.$n.'</option>';
                        }
                        $elementHtml .= '</optgroup>';
                     } else {
                        $selected = (isset($k[1]['value']) && (in_array($optionValue, $k[1]['value'])))?'selected="selected"':'';
                        $elementHtml .= '<option value="'.$optionValue.'" '.$selected.'>'.$optionName.'</option>';
                     }
                  }
               }
               $elementHtml .= '</select></'.$elementWrapper.'>';
               break;


and the code for line 241to add MulitSelect

Code: Select all
         // handle values for all fields except select, checkbox, radio, multiselect, multiradio, multicheckbox...
         if (($k[0] != 'select') && ($k[0] != 'MultiCheckbox') && ($k[0] != 'MultiRadio') && ($k[0] != 'MultiSelect') && ($k[0] != 'checkbox') && ($k[0] != 'textarea')) {
            if (isset($elementValues[$element])) {
               $elementAttributes .= ' value="'.htmlspecialchars($elementValues[$element]).'"';
            }
         }
Image
chucka
 
Posts: 101
Joined: Tue Oct 06, 2009 7:39 pm

Re: Select Multiple

Postby leng » Tue Dec 29, 2009 7:48 pm

I think it's nice. Not sure what others think about this. Milos, if you read this, do you see any possible conflict/problems with the existing DooForm source ?
Just Doo IT!
leng
 
Posts: 1482
Joined: Thu Jul 16, 2009 11:33 pm

Re: Select Multiple

Postby Mil0s » Fri Jan 01, 2010 5:21 pm

Hey, I came back, I added MultiSelect to DooForm, tnx chucka I totaly forgot about it :)
Keep it fast and keep it simple!
DooPhp
Mil0s
 
Posts: 221
Joined: Mon Aug 31, 2009 2:15 pm
Location: Serbia

Re: Select Multiple

Postby chucka » Mon Jan 04, 2010 3:40 pm

Sweet!

This is how I'm using it in one of my DooForm calls just as an example.

Code: Select all
'components' => array('MultiSelect', array(
   'required' => false,
   'attributes' => array('style'=>'width: 600px; height: 300px;'),
   'value' => (array_key_exists('selectedComponents',$this->data)) ? $this->data['selectedComponents'] : null,
   'multioptions' => $this->data['components'],
   'wrapper' => 'div',
   'label' => 'Components in Category:'
)),
Image
chucka
 
Posts: 101
Joined: Tue Oct 06, 2009 7:39 pm


Return to Features Request

Who is online

Users browsing this forum: No registered users and 1 guest

cron