Dynamic Picking List

I have a few dynamic picking lists that work nicely (using MAR). I
want to be able to select multiple items at once instead of just one.
I found a couple examples but have been unable to implement them yet.
Anyone know of an online resource/example/tut that might help with this?

Todd


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Todd,
Picking multiple items from the same list or multiple lists?
The multiple attribute on the select tag will let the user choose
multiple items from the list;

Regards,
Tim.

On 27 Jun 2009, at 18:01, Todd wrote:

I have a few dynamic picking lists that work nicely (using MAR). I
want to be able to select multiple items at once instead of just
one. I found a couple examples but have been unable to implement
them yet. Anyone know of an online resource/example/tut that might
help with this?

FreewayActions.com - Freeware and shareware actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Yeah, but the multiple picker is such a pain to use (and so
infrequently used) that it’s just an unfamiliar and unpleasant way to
address the problem.

What I do is present an array of checkboxes, one per option. That
usually maps neatly to the user’s understanding of what the question
is. All of these checkboxes are named the same, but with array
notation to carry the ID they apply to.

On the controller side, you would loop through the current data and
unset all of it, then set the new information from the POST.

Here’s an example, torn from the headlines:

A Product can have many Parts. There is a parts_products table to map
this relationship sitting between them. As the admin creates a new
Product, she sees a list of checkboxes for each of the available
Parts. In HTML, this looks like so:

<label for="part_123"><input type="checkbox" id="part_123"  
name="part[123]" value="1" /> foo</label>
<label for="part_129"><input type="checkbox" id="part_129"  
name="part[129]" value="1" /> bar</label>
<label for="part_133"><input type="checkbox" id="part_133"  
name="part[133]" value="1" /> baz</label>

If all of these checkboxes were checked and the form was submitted,
you would see a post variable like this:

Array(
	123=>1,
	129=>1,
	133=>1
)

So to process this on the server, you would do this:

if($product = ActiveRecord::FindById('products',$id)){
	//put the rest of your editing form into place
	$product->populate($_POST);
	$product->save();
	if($product->get_errors() == false){
		foreach($product->find_attached('parts') as $p) $product->detach($p);
		//or, less stress on the database, not as neat and OO
		//ActiveRecord::Query('DELETE FROM parts_products WHERE products_id  
== ' . $id);
		foreach($_POST['part'] as $k=>$v){
			if($part = ActiveRecord::FIndById('parts',$k)) $product- 
 >attach($part);
		}
	}
}

Now, no matter what combination of checkboxes were pressed, there is
only one matching row for each in the link table.

Walter

On Jun 29, 2009, at 2:17 AM, Tim Plumb wrote:

Hi Todd,
Picking multiple items from the same list or multiple lists?
The multiple attribute on the select tag will let the user choose
multiple items from the list;
HTML select multiple Attribute
Regards,
Tim.

On 27 Jun 2009, at 18:01, Todd wrote:

I have a few dynamic picking lists that work nicely (using MAR). I
want to be able to select multiple items at once instead of just
one. I found a couple examples but have been unable to implement
them yet. Anyone know of an online resource/example/tut that might
help with this?

FreewayActions.com - Freeware and shareware actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Tim & Walter.

Tim’s suggestion is what I originally had in mind mainly because it
cuts down on checkbox clutter. I did try to implement the multiple
attribute a few days ago but couldn’t see how to add it to the
tag because the pickers are dynamically generated. It worked
fine for me with static pickers, though.

Walter, I see your point and I’ll try to implement your technique,
perhaps it won’t look as cluttered once I actually see the layout with
the checkboxes.

For a bit more info, in this demo http://anoptic.com/MAR/client/ the
2 picking lists “software” and “languages” are the ones I want to have
the multiple select feature.

Todd

On Jun 29, 2009, at 7:52 AM, Walter Lee Davis wrote:

Yeah, but the multiple picker is such a pain to use (and so
infrequently used) that it’s just an unfamiliar and unpleasant way
to address the problem.

What I do is present an array of checkboxes, one per option. That
usually maps neatly to the user’s understanding of what the question
is. All of these checkboxes are named the same, but with array
notation to carry the ID they apply to.
On Jun 29, 2009, at 2:17 AM, Tim Plumb wrote:

Hi Todd,
Picking multiple items from the same list or multiple lists?
The multiple attribute on the select tag will let the user choose
multiple items from the list;
HTML select multiple Attribute
Regards,
Tim.

On 27 Jun 2009, at 18:01, Todd wrote:

I have a few dynamic picking lists that work nicely (using MAR). I
want to be able to select multiple items at once instead of just
one. I found a couple examples but have been unable to implement
them yet. Anyone know of an online resource/example/tut that might
help with this?


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

How are you modelling these? Is there a people_software table, for
example?

Walter

PS: The link in your footer is to the out-of-date PHPClasses site for
MAR. Jake hasn’t touched that in years. You might consider linking to
my GitHub fork instead…

On Jun 29, 2009, at 9:53 AM, Todd wrote:

For a bit more info, in this demo http://anoptic.com/MAR/client/
the 2 picking lists “software” and “languages” are the ones I want
to have the multiple select feature.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Just one table for everything, “mar”.

I changed the link to your GitHUb. Thanks.

Todd

On Jun 29, 2009, at 9:02 AM, Walter Lee Davis wrote:

How are you modelling these? Is there a people_software table, for
example?

PS: The link in your footer is to the out-of-date PHPClasses site
for MAR. Jake hasn’t touched that in years. You might consider
linking to my GitHub fork instead…


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

In that case, you have no place to store multiple choices. You have a
single field named ‘software’, for example, and that by definition may
only carry one value. To store multiple values, you will need another
table and a link table between them to carry the “attachments”.

software
	id
	name

people
	id
	name
	...

people_software
	people_id
	software_id

$person = ActiveRecord::FIndFirst('people');
$software = array_keys($person->find_attached('software'));
foreach(ActiveRecord::FindAll('software') as $s){
	$linked = (in_array($s->id,$software)) ? ' checked="checked"' : '';
	$out .= '<label for="software_' . $s->id . '"><input type="checkbox"
		id="software_' . $s->id . '" name="software[' . $s->id . ']"
		value="1"' . $checked . '  /> ' . $s->h('name') . '</label>';
}

Walter

On Jun 29, 2009, at 10:07 AM, Todd wrote:

Just one table for everything, “mar”.

I changed the link to your GitHUb. Thanks.

Todd

On Jun 29, 2009, at 9:02 AM, Walter Lee Davis wrote:

How are you modelling these? Is there a people_software table, for
example?

PS: The link in your footer is to the out-of-date PHPClasses site
for MAR. Jake hasn’t touched that in years. You might consider
linking to my GitHub fork instead…


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I’ll give this a shot, thanks.

Alternatively, if I did want to try the multiple picker option like
Tim suggested

how/where would I add the attribute to the pickers since the tags get
generated on-the-fly?

Todd

On Jun 29, 2009, at 9:27 AM, Walter Lee Davis wrote:

In that case, you have no place to store multiple choices. You have
a single field named ‘software’, for example, and that by definition
may only carry one value. To store multiple values, you will need
another table and a link table between them to carry the
“attachments”.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I don’t remember exactly how a multiple picker sends its values. It
obviously sends them as an array, I just can’t remember whether the
values are on the keys or the values side of the array.

Try making a simple static form with a single multiple picker, post to
itself, and look at print_r($_POST) to see what’s there.

Walter

On Jun 29, 2009, at 11:23 AM, Todd wrote:

I’ll give this a shot, thanks.

Alternatively, if I did want to try the multiple picker option like
Tim suggested

how/where would I add the attribute to the pickers since the tags
get generated on-the-fly?

Todd

On Jun 29, 2009, at 9:27 AM, Walter Lee Davis wrote:

In that case, you have no place to store multiple choices. You have
a single field named ‘software’, for example, and that by
definition may only carry one value. To store multiple values, you
will need another table and a link table between them to carry the
“attachments”.


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options