From jeff.barczewski at gmail.com Fri Jul 15 10:38:40 2005
From: jeff.barczewski at gmail.com (Jeff Barczewski)
Date: Fri Jul 15 10:33:23 2005
Subject: [Amrita2-users] Amrita2 Question about how to use select and
checkbox with a collection,
or ideas on how I can extend Amrita to do this
Message-ID: <19cda19050715073843b79b@mail.gmail.com>
I was trying to figure out if there is a way to use select in Amrita2
with a collection (array, Enumeration, ...)
For instance I would like to do something like
and I would somehow give it an array of values
optionValues = [
["a","aaa"],
["b","ghi"],
["c","jkl"]
]
>From what I can tell with the examples it only shows select being used
for a static predefined option list like so
However for database driven applications, most of the time these
options are queried from the database and then dynamically filled into
the select box at runtime. Since Amrita does a nice job of iterating
on a collection this by itself is easy, however I don't know if it is
possible to combine the functionality so that the collection creates
the option values, and the select knows which one to mark as
'selected'.
Maybe one would even simply the syntax and just do something like
Similarly it would be nice to be able to do a similar thing with
checkboxes such that a whole collection of them can be rendered based
on a collection of values and a collection of selected values.
where checkboxes would be a collection of checkbox values and
descriptions, and selValues would be a collection of the selected
values.
Anyway, if anyone has any ideas how this can be done currently in
Amrita2 I would appreciate any help. Otherwise if there are
suggestions on how I might extend Amrita2 to add this functionality I
would like to help to do that as well, I just need to be pointed in
the right direction and maybe given an idea on how to do a plugin or
what is needed.
Thanks for your help,
Jeff Barczewski
From tnakajima at brain-tokyo.jp Tue Jul 19 04:26:09 2005
From: tnakajima at brain-tokyo.jp (Taku Nakajima)
Date: Tue Jul 19 04:20:47 2005
Subject: [Amrita2-users] Amrita2 Question about how to use select
and checkbox with a collection,
or ideas on how I can extend Amrita to do this
In-Reply-To: <19cda19050715073843b79b@mail.gmail.com>
References: <19cda19050715073843b79b@mail.gmail.com>
Message-ID:
At Fri, 15 Jul 2005 09:38:40 -0500,
Jeff Barczewski wrote:
>
> I was trying to figure out if there is a way to use select in Amrita2
> with a collection (array, Enumeration, ...)
Here is how to deal
END
optionValues = [
["a","aaa"],
["b","ghi"],
["c","jkl"]
]
selected = optionValues[rand(3)]
p selected
data = {
:optValues=>optionValues.collect do |v, str|
if selected[0] == v
a(:value=>v, :selected=>'selected') { str }
else
a(:value=>v) { str }
end
end
}
t.expand(STDOUT, data)
# when options are given with template
t = TemplateText.new <
END
optionValues = %w(a b c)
selected = optionValues[rand(3)]
p selected
data = {
:sel1=>selected
}
t.expand(STDOUT, data)
------------------------------------------------------------------------
$ ruby -Iamrita2/lib select.rb
["b", "ghi"]
"c"
------------------------------------------------------------------------
For detail of a(...) { ... } , see
http://amrita2.rubyforge.org/QuickStart.html
Step 3: attribute handling/ AttrArray object
---
Taku Nakajima