Re: Re: QuickForm_advmultiselect - can you open the form with the SELECTED list already populated from a data set?
| From: | l Burnerheimerton | Date: | Mon, 29 Aug 2005 21:02:28 +0000 |
| Subject: | Re: Re: QuickForm_advmultiselect - can you open the form with the SELECTED list already populated from a data set? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20642@lists.php.net to get a copy of this message | ||
--- Laurent Laville <pear@laurent-laville.org> wrote:
> l Burnerheimerton wrote:
> > I'd like to use this to change who is selected for
> new
> > AND existing selections.
> >
> > I have two data arrays I can pass:
> > - a list of available options (AVAILABLE)
> > - a list of options I've already chosen (SELECTED)
> >
> > I'd like to know how to populate the two select
> fields
> > with these two data sets.
> >
> > For example, imagine using this for selecting OR
> > changing what is in your shopping cart. If I
> already
> > have a cart, I want those items to populate the
> > SELECTED list.
> >
> > Is this possible? If not, it would be a great(!)
> feature.
>
> advmultiselect is a QuickForm element and has
> nosense without a form
> but data can come from any data sources you might
> want.
>
> Perharps i've not understand the question, but it
> seems easy to
> set (in your case) the two select boxes with the two
> data sets.
>
> $AVAILABLE = [your AVAILABLE data set];
> $SELECTED = [your options already choosen data
> set];
>
> $form = new HTML_QuickForm();
> $form->addElement('advmultiselect', 'amsList', null,
> $AVAILABLE);
> $form->setDefaults(array('amsList' => $SELECTED));
>
> Laurent
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
thanks. based on this, I tried the code below. A
blank entry displays in the selected option list - you
can select it but it has no label/name to it.
print_r() verifies there is an array of values getting
to both.
$form = new HTML_QuickForm('amsCustom1');
$form->removeAttribute('name'); // XHTML
compliance
//get list of services
$all_people = $db->getAssoc("SELECT ...");
$selected_people = $db->getAssoc("SELECT ...");
print_r($all_students);
print_r($selected_students);
$form->setDefaults(array( //set form field defaults
'people' => array('people' => $selected_people)
)
);
// rendering with QF renderer engine and template
system
$form->addElement('header', null, 'Advanced Multiple
Select: custom layout ');
$ams =& $form->addElement('advmultiselect', 'people',
null, $all_people,
array('size' => 10,
'class' => 'pool',
'style' => 'width:150px;'
)
);
$ams->setLabel(array('people:', 'Available',
'Selected'));
$ams->setButtonAttributes('add', array('value' =>
'Add >>',
'class' =>
'inputCommand'
));
$ams->setButtonAttributes('remove', array('value' =>
'<< Remove',
'class' =>
'inputCommand'
));
$template = '
<table{class}>
==========================================
Now here's a snippet of what is rendered:
<td><select size="10" style="width:150px;"
name="__people[]" multiple="multiple"
ondblclick="moveSelections(this.form.elements['__people[]'],
this.form.elements['_people[]'],
this.form.elements['people[]'], 'add')">
<option value="16">Jim, Jim</option>
</select></td>
<td><select size="10" style="width:150px;"
name="_people[]" multiple="multiple"
ondblclick="moveSelections(this.form.elements['__people[]'],
this.form.elements['_people[]'],
this.form.elements['people[]'], 'remove')">
<option> </option>
</select><select size="10" style="overflow: hidden;
visibility: hidden; width: 1px; height: 0;"
name="people[]" multiple="multiple">
<option> </option>
<option value="16">Jim, Jim</option>
</select></td>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com