[Hobo Users] Filter-menu Optgroups?

11 views
Skip to first unread message

paulo

unread,
May 19, 2010, 5:27:40 AM5/19/10
to Hobo Users
Hi all,

Is it possible to use optgroups within a filter-menu? I am creating an
array within my controller to populate my filter-menus but am not sure
how I could implement these groups within the menu / options array?

Thanks in advance.

Paul

--
You received this message because you are subscribed to the Google Groups "Hobo Users" group.
To post to this group, send email to hobo...@googlegroups.com.
To unsubscribe from this group, send email to hobousers+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.

paulo

unread,
May 19, 2010, 5:44:16 AM5/19/10
to Hobo Users
Sorry, another quick (and really simple I'm sure) question as well
about filter-menu's:

In defining custom options for a filter-menu, I am providing an array
of pairs i.e. the post value and the display value. In this case, its
dates so for example, I want my filter to post '2010-01-01' but to
display 'January 2010'. This works fine but when the page refreshes on-
change, the filter-menu is not pre-selecting the current option
applied. I presume it is comparing the two different formats and not
getting a match, thus defaulting to 'All'.

Is there a way to avoid this behavior?

Again, many thanks


Paul

Bryan Larsen

unread,
May 19, 2010, 11:48:17 AM5/19/10
to Hobo Users
This looks like a bug to me. It appears that we're calling "to_s" on
your pair to determine the current selection. It's even worse than
you thought: it's not comparing the wrong format, it's comparing
against a combination of the 2!. I opened
https://hobo.lighthouseapp.com/projects/8324-hobo/tickets/new to deal
with it.

Bryan

Bryan Larsen

unread,
May 19, 2010, 12:00:38 PM5/19/10
to Hobo Users
Hobo uses Rails' options_for_select to do its heavy lifting. If you
patch rails with
https://rails.lighthouseapp.com/projects/8994/tickets/1986-create-optgroups-in-options_for_select,
you'll get the desired behaviour.

Note that the rails patch was produced by our resident expert Matt
Jones. It's too bad they rejected the patch. :(

Another option would be to patch select-menu so that it used
grouped_options_for_select instead of options_for_select when
appropriate. I'm not exactly sure what the interface should be --
perhaps if options were passed in via a "grouped-options" attribute
rather than "options". If you create such a patch, I'd love to add
it to Hobo.

Bryan

Bryan Larsen

unread,
May 19, 2010, 12:01:56 PM5/19/10
to Hobo Users
hehe, that link is
https://hobo.lighthouseapp.com/projects/8324-hobo/tickets/725-filter-menu-does-not-properly-determine-current-selection

On May 19, 11:48 am, Bryan Larsen <bryan.lar...@gmail.com> wrote:
> This looks like a bug to me.   It appears that we're calling "to_s" on
> your pair to determine the current selection.   It's even worse than
> you thought:  it's not comparing the wrong format, it's comparing
> against a combination of the 2!. I openedhttps://hobo.lighthouseapp.com/projects/8324-hobo/tickets/newto deal

Matt Jones

unread,
May 19, 2010, 9:05:46 PM5/19/10
to hobo...@googlegroups.com

On May 19, 2010, at 12:00 PM, Bryan Larsen wrote:

> Hobo uses Rails' options_for_select to do its heavy lifting. If you
> patch rails with
> https://rails.lighthouseapp.com/projects/8994/tickets/1986-create-optgroups-in-options_for_select
> ,
> you'll get the desired behaviour.
>
> Note that the rails patch was produced by our resident expert Matt
> Jones. It's too bad they rejected the patch. :(
>

A bummer indeed, although Pratik's comment is reasonable -
options_for_select does tons of stuff already.

> Another option would be to patch select-menu so that it used
> grouped_options_for_select instead of options_for_select when
> appropriate. I'm not exactly sure what the interface should be --
> perhaps if options were passed in via a "grouped-options" attribute
> rather than "options". If you create such a patch, I'd love to add
> it to Hobo.

The third option (which I actually have used) is to punt - at it's
core, filter-menu is *not* a terribly complicated tag. All it is
(minus some of the defaulting, parameter merging, etc) is:

<form action="&request.request_uri" method="get" class="filter-menu">
<div>
...a select menu, generated by *some* means, lives here...
</div>
</form>

Not exactly a complicated tag. The unobtrusive scripts in hobo-
rapid.js take care of wiring up the select menu -> form submit stuff
(as long as the filter-menu class is there).

--Matt Jones

paulo

unread,
May 21, 2010, 7:01:13 AM5/21/10
to Hobo Users
Thanks for that, I just created a manual 'select' tag for the time
being, until that issue is resolved.

In terms of the optgroups, I've put it on the backburner for the time
being, might look into creating a patch when I've got a bit more time/
experience in HOBO


Cheers,

Paul

On May 20, 2:05 am, Matt Jones <al2o...@gmail.com> wrote:
> On May 19, 2010, at 12:00 PM, Bryan Larsen wrote:
>
> > Hobo uses Rails' options_for_select to do its heavy lifting.  If you
> > patch rails with
> >https://rails.lighthouseapp.com/projects/8994/tickets/1986-create-opt...
Reply all
Reply to author
Forward
0 new messages