DRYML multi-select dropdown vs. model with enum_string

16 views
Skip to first unread message

Donald Ziesig

unread,
Mar 15, 2017, 11:08:23 AM3/15/17
to Hobo Users
Hi All!

Hobo has been working great for me for years now, but I just ran into
something that I can't figure out (maybe because I'm now 74 years old :-D ).

I have an app that uses enum_string in one of the fields to produce a
standard drop down list. No Problem.

I want to change it so that I can populate the drop down list from two
static texts and the contents of one of the fields of a second table.

The original code is:

fields do
name :string, :index => true
*
*
send_to enum_string('Active Members','Trustees','Specified')
*
*
end

I changed this field to

send_to string

which changed the rendered form to use a plain input box.

I want to produce a drop down list that looks like this:

Active Members
Trustees
AMember #populated from Members table
BMember
CMember
*
ZMember

etc.

where the user can select multiple entries.

The current form contains the following:

<field-list fields="subject, body, send_to, specified" param>
<specified-label:>#{ht 'club_email.labels.specified',
:default=>'DEFAULT'}</specified-label:>
<body-label:></body-label:>
</field-list>

The impacted field is send_to.

Bonus points if the solution only allows multi-select for the
AMember..ZMember but not if one of Active Members or Trustees is
selected. (I'll handle this in code otherwise).

Is there an easy way of doing this? I looked in the documentation, but
could not find a combination to do this without using custom DRYML.

Thanks,

Don Ziesig


Ibon Castilla

unread,
Mar 16, 2017, 2:41:41 AM3/16/17
to hobo...@googlegroups.com
Hi Don,

I would do it overriding <send-to-view:> tag, and adding a select-menu
DRYML tag (or equivalent). You can populate options' values with the
names you want.
Set that select control name exactly with the same name as the Hobo
automatic plain string input and you are done: your send_to field will
be filled perfectly well :)

Best regards, Ibon.

Abrazo, Ibon.

Usa Software Libre, tus úlceras te lo agradecerán
Realizado con Software Libre.
--
GPG public key at http://sinanimodelucro.net/ibon_gmail.asc
Finderprint: 1761 59B9 6DE6 0402 31B9 1872 178F A6FD 75F9 EB29

El 15/03/17 a las 16:07, Donald Ziesig escribió:
signature.asc

Ed Gomolka

unread,
Mar 16, 2017, 9:32:36 PM3/16/17
to Hobo Users
Hi:

In the case of a has_many :through association, I happily use Hobo's select-many tag; however, it sounds like you have a different situation.

I suggest that you take a look at the Rails select_tag: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-select_tag
It can be set up for multiple selections, and it looks to me like you should be able to combine table-driven and static selection options. Here is a code snippet showing how I have embedded the tag into a dryml page:


          <role_select-view:>
            <%= select_tag "role_select", options_from_collection_for_select(Role.order(:name).all, "id", "name", :selected => @user.roles.pluck(:id)),  multiple: true,  :size => 10, :style=>'width:300px' %>
          </role_select-view:>

Good luck!

Ed G
Reply all
Reply to author
Forward
0 new messages