How to initially hide a drop-down control and have an image control make it visible

10 views
Skip to first unread message

RichardOnRails

unread,
Mar 21, 2010, 12:07:23 AM3/21/10
to Ruby on Rails: Talk
Hi,

I've got the following code in my attempt to provide the subject
functionality, lines 20-29 in view:

<%= image_tag "DownArrow.jpg" options =
{ onclick=page["vendor_droplist"].show } %>
<br>
<div name="vendor_droplist">
<%= select_tag "test",
options_for_select(@current_vendors.collect { |v|
v.nickname }),
{:multiple => true} %>
</div>

Until I put in the options on image tag and added the div, this code
display a list of vendor nicknames. Now I have several problems:

1. Syntax error in line 20 where an identifier was encountered where a
right-paren was expected (see below)
2. I don't know how to make the vendor_droplist initially hidden

I've Googled for "Rails Ajax toggled item" and got a number of hits
but no apparent answer. I'll keep poking around the Web, but I
appreciate some suggestion(s).

Thanks in advance,
Richard

Showing app/views/expenses/new.html.erb where line #20 raised:

compile error
K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/views/expenses/
new.html.erb:20: syntax error, unexpected tIDENTIFIER, expecting ')'
@output_buffer.concat " "; @output_buffer.concat(( image_tag
"DownArrow.jpg" options =
{ onclick=page["vendor_droplist"].show } ).to_s);
@output_buffer.concat "\n"

^
K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/views/expenses/
new.html.erb:20: odd number list for Hash
@output_buffer.concat " "; @output_buffer.concat(( image_tag
"DownArrow.jpg" options =
{ onclick=page["vendor_droplist"].show } ).to_s);
@output_buffer.concat "\n"

^

Extracted source (around line #20):

17: <p>
18: <%= f.label :vendor %><br />
19: <%= f.text_field :vendor %>
20: <%= image_tag "DownArrow.jpg" options =
{ onclick=page["vendor_droplist"].show } %>
21: <br>
22: <div name="vendor_droplist">
23: <%= select_tag "test",

Trace of template inclusion: app/views/expenses/new.html.erb

RAILS_ROOT: K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS
Application Trace | Framework Trace | Full Trace

K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/views/expenses/
new.html.erb:59:in `compile!'
K:/_Projects/Ruby/_Rails_Apps/_EIMS/RTS/app/controllers/
expenses_controller.rb:30:in `new'

RichardOnRails

unread,
Mar 21, 2010, 12:33:37 AM3/21/10
to Ruby on Rails: Talk
I think I corrected the div by:
1. giving it an id rather than a name
2. adding display:none to start it off hidden
as follows:

<%# = image_tag "DownArrow.jpg" options =


{ onclick=page["vendor_droplist"].show } %>
<br>

<div id="vendor_droplist", style="display:none">


<%= select_tag "test",
options_for_select(@current_vendors.collect { |v|
v.nickname }),
{:multiple => true} %>
</div>


On Mar 21, 12:07 am, RichardOnRails

RichardOnRails

unread,
Mar 21, 2010, 12:37:41 AM3/21/10
to Ruby on Rails: Talk
I think I improved two things in the version of lines 20-26 below:
1. I gave the div an id rather than a name
2. I gave the div a style of "display:none" so that it's hidden at
every startup of the view

<%# = image_tag "DownArrow.jpg" options =


{ onclick=page["vendor_droplist"].show } %>
<br>

<div id="vendor_droplist", style="display:none">

<%= select_tag "test",
options_for_select(@current_vendors.collect { |v|
v.nickname }),
{:multiple => true} %>
</div>

On Mar 21, 12:07 am, RichardOnRails
<RichardDummyMailbox58...@USComputerGurus.com> wrote:

RichardOnRails

unread,
Mar 21, 2010, 1:02:36 AM3/21/10
to Ruby on Rails: Talk
OK, I got rid of all the syntax errors.
The vendor_drop list is now hidden on startup of the view
I switched from an image to a button
However, the drop list does not get displayed when the ShowList button
is clicked
Code is below. Ideas are most welcome


<%= button_to_function("ShowList",
%<page["vendor_droplist"].show> ) %>


<br>
<div id="vendor_droplist", style="display:none">
<%= select_tag "test",
options_for_select(@current_vendors.collect { |v|
v.nickname }),
{:multiple => true} %>
</div>


On Mar 21, 12:37 am, RichardOnRails

Colin Law

unread,
Mar 21, 2010, 5:04:40 AM3/21/10
to rubyonra...@googlegroups.com
On 21 March 2010 04:07, RichardOnRails

<RichardDummy...@uscomputergurus.com> wrote:
> Hi,
>
> I've got the following code in my attempt to provide the subject
> functionality, lines 20-29 in view:
>
>    <%= image_tag "DownArrow.jpg" options =
> { onclick=page["vendor_droplist"].show } %>

I don't know whether it is still relevant after your later emails but
the problem here is (at least in part) that you are missing a comma
after "DownArrow.jpg" and a > after options =

Colin

Colin Law

unread,
Mar 21, 2010, 5:11:01 AM3/21/10
to rubyonra...@googlegroups.com
On 21 March 2010 05:02, RichardOnRails

<RichardDummy...@uscomputergurus.com> wrote:
> OK,  I got rid of all the syntax errors.
> The vendor_drop list is now hidden on startup of the view
> I switched from an image to a button
> However, the drop list does not get displayed when the ShowList button
> is clicked
> Code is below.  Ideas are most welcome
>
>
>    <%= button_to_function("ShowList",
> %<page["vendor_droplist"].show> ) %>

Have you checked the html generated by the above to make sure it is
generating what you expect?

Colin

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

RichardOnRails

unread,
Mar 21, 2010, 6:49:53 AM3/21/10
to Ruby on Rails: Talk
Hi Colin,

Your "check the HTML" tip is *great* ... it's now in my debugging
arsenal.

> comma missing
That was a tip on my img-base code. I'll get back to that because I
like the down-arrow image better that ShowList button version, which
is close to working.

My last next-to-last problem in this code is that the ShowList button
doesn't toggle the visibility of the vendor_droplist. My guess is
that the onclick value is RJS that should have been translated into
JavaScript at this point.

My final problem is how to add on-click code to the return vendor
items so that clicking any of them toggles (or hides: same effect in
this context) the vendor_droplist. But I can probably do this on my
own correctly.

Below is the ERB code and the generated HTML for the vendor input. As
I've done so often, thank you for looking into my problem. I am
learning this stuff steadily so I should post questions much less
frequently in just a few weeks.

Best wishes,
Richard

Vendor input code
=============
<p>


<%= f.label :vendor %><br />

<%= f.text_field :vendor %>
<%= button_to_function("ShowList",
%<page[:vendor_droplist].toggle> ) %>


<br>
<div id="vendor_droplist", style="display:none">

<%= select_tag "test",
options_for_select(@current_vendors.collect { |v|
v.nickname }),
{:multiple => true} %>
</div>

</p>

Generated HTML
============
<p>
<label for="expense_vendor">Vendor</label><br />

<input id="expense_vendor" name="expense[vendor]" size="30"
type="text" />
<input onclick="page[:vendor_droplist].toggle;" type="button"
value="ShowList" />


<br>
<div id="vendor_droplist", style="display:none">

<select id="test" multiple="multiple" name="test[]"><option
value="IBM">IBM</option>
<option value="Fed Ex">Fed Ex</option></select>
</div>
</p>


On Mar 21, 5:04 am, Colin Law <clan...@googlemail.com> wrote:
> On 21 March 2010 04:07, RichardOnRails
>

Colin Law

unread,
Mar 21, 2010, 10:18:45 AM3/21/10
to rubyonra...@googlegroups.com
On 21 March 2010 10:49, RichardOnRails

<RichardDummy...@uscomputergurus.com> wrote:
> Hi Colin,
>
> Your "check the HTML" tip is *great* ... it's now in my debugging
> arsenal.

Another tip is to install the Html Validator add-on to Firefox and it
will automatically validate your pages as you develop, this often
shows up the reason why something is not working as you expect.

Colin

RichardOnRails

unread,
Mar 22, 2010, 4:35:25 PM3/22/10
to Ruby on Rails: Talk
Hey Colin,

Your "how's the HTML" question really did the job:
<div> tag not allowed within the scope of a <form> tag.

Which means the my .erb can't have:

<% form_for(@expense) do |f| %>
[snip]
<div id="vendor_droplist" style="display:none">


<%= select_tag "test",
options_for_select(@current_vendors.collect { |v|
v.nickname }),
{:multiple => true} %>
</div>

More importantly to me, it means that:

<input onclick="page.toggle :vendor_droplist;" type="button"
value="ShowList" />

won't work inside that form.

I'm going to post a new question on how to fix this while I scour the
documentation to figure it out myself.

Again, thank you for sharing your expertise with me,
Richard


On Mar 21, 10:18 am, Colin Law <clan...@googlemail.com> wrote:
> On 21 March 2010 10:49, RichardOnRails
>

> <RichardDummyMailbox58...@uscomputergurus.com> wrote:
> > Hi Colin,
>
> > Your "check the HTML" tip is *great* ... it's now in my debugging
> > arsenal.
>
> Another tip is to install the Html Validator add-on to Firefox and it
> will automatically validate your pages as you develop, this often
> shows up the reason why something is not working as you expect.
>
> Colin


On Mar 21, 10:18 am, Colin Law <clan...@googlemail.com> wrote:
> On 21 March 2010 10:49, RichardOnRails
>

Hassan Schroeder

unread,
Mar 22, 2010, 4:51:28 PM3/22/10
to rubyonra...@googlegroups.com
On Mon, Mar 22, 2010 at 1:35 PM, RichardOnRails
<RichardDummy...@uscomputergurus.com> wrote:

> Your "how's the HTML" question really did the job:
> <div> tag not allowed within the scope of a <form> tag.

What gives you that idea? It's simply not true.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan

RichardOnRails

unread,
Mar 22, 2010, 5:51:33 PM3/22/10
to Ruby on Rails: Talk
Hi Hassan,

Thanks for joining the conversation. I ran my the HTML page which was
generated by my .erb. I had a form_for with an embedded div and the
HTML page had an embedded div. W3C didn't like it. The details are
at http://www.pastie.org/881730. Now that I look at it again,
perhaps the Object tag in place of the Div will work.

Best wishes,
Richard

On Mar 22, 4:51 pm, Hassan Schroeder <hassan.schroe...@gmail.com>
wrote:


> On Mon, Mar 22, 2010 at 1:35 PM, RichardOnRails
>

> <RichardDummyMailbox58...@uscomputergurus.com> wrote:
> > Your "how's the HTML" question really did the job:
> > <div> tag not allowed within the scope of a <form> tag.
>
> What gives you that idea? It's simply not true.
>
> --

> Hassan Schroeder ------------------------ hassan.schroe...@gmail.com
> twitter: @hassan

Michael Pavling

unread,
Mar 22, 2010, 6:02:37 PM3/22/10
to rubyonra...@googlegroups.com
On 22 March 2010 21:51, RichardOnRails

<RichardDummy...@uscomputergurus.com> wrote:
> Hi Hassan,
>
> Thanks for joining the conversation.  I ran my the HTML page which was
> generated by my .erb.  I had a form_for with an embedded div and the
> HTML page had an embedded div.  W3C didn't like it.  The details are
> at http://www.pastie.org/881730.  Now that I look at it again,
> perhaps the Object tag in place of the Div will work.

It's not that you have a <form> with a nested <div> that the W3C is
complaining at, it's that you have a <p> with a nested <div> - lines
33 and 39 of your NewExpensePage.htm

Hassan Schroeder

unread,
Mar 22, 2010, 6:11:14 PM3/22/10
to rubyonra...@googlegroups.com
On Mon, Mar 22, 2010 at 2:51 PM, RichardOnRails
<RichardDummy...@uscomputergurus.com> wrote:

> Thanks for joining the conversation.  I ran my the HTML page which was
> generated by my .erb.  I had a form_for with an embedded div and the
> HTML page had an embedded div.  W3C didn't like it.  The details are
> at http://www.pastie.org/881730.

Read line 11 of your validation pastie -- that is almost certainly your
problem.

Getting used to reading the HTML DTD(s) would be a good idea :-)

RichardOnRails

unread,
Mar 23, 2010, 3:14:09 AM3/23/10
to Ruby on Rails: Talk
Great response, Michael. I now have a clean validation on the
compiled code, but I've still got a problem.

I've got clean code that validates. http://www.pastie.org/882256
displays:
- new.html.erb
- HTML generated for new.html.erb
- Validation for generated html, which has one spurious (IMHO) warning

The code that's problematic for me is:
<%# This begins the vendor-name code %>


<%= f.label :vendor %><br />
<%= f.text_field :vendor %>
<%= button_to_function("ShowList",
%<page["vendor_droplist"].toggle> ) %>

<br />


<div id="vendor_droplist" style="display:none">

<%= select_tag "list",
options_for_select(@current_vendors),
:multiple => true, :size => 3 %>
</div>
<%# This is the end of the vendor-name code %>

The vendor_droplist without the style allows vendors to be displayed
in a drop-down-style list.
With the "hide style", I expected that clicking the ShowList button
would cause the list to be displayed, but that does not happen.

Do you any further idea about how to get that button working?

Thanks in Advance for any other ideas you may have.

On Mar 22, 6:02 pm, Michael Pavling <pavl...@gmail.com> wrote:
> On 22 March 2010 21:51, RichardOnRails
>

> <RichardDummyMailbox58...@uscomputergurus.com> wrote:
> > Hi Hassan,
>
> > Thanks for joining the conversation. I ran my the HTML page which was
> > generated by my .erb. I had a form_for with an embedded div and the
> > HTML page had an embedded div. W3C didn't like it. The details are

> > athttp://www.pastie.org/881730. Now that I look at it again,


> > perhaps the Object tag in place of the Div will work.
>
> It's not that you have a <form> with a nested <div> that the W3C is
> complaining at, it's that you have a <p> with a nested <div> - lines
> 33 and 39 of your NewExpensePage.htm

On Mar 22, 6:02 pm, Michael Pavling <pavl...@gmail.com> wrote:
> On 22 March 2010 21:51, RichardOnRails
>

> <RichardDummyMailbox58...@uscomputergurus.com> wrote:
> > Hi Hassan,
>
> > Thanks for joining the conversation.  I ran my the HTML page which was
> > generated by my .erb.  I had a form_for with an embedded div and the
> > HTML page had an embedded div.  W3C didn't like it.  The details are

> > athttp://www.pastie.org/881730.  Now that I look at it again,

RichardOnRails

unread,
Mar 23, 2010, 3:15:09 AM3/23/10
to Ruby on Rails: Talk
Hi Hassan, please take a look at my reply to Michael.

On Mar 22, 6:11 pm, Hassan Schroeder <hassan.schroe...@gmail.com>
wrote:


> On Mon, Mar 22, 2010 at 2:51 PM, RichardOnRails
>

> <RichardDummyMailbox58...@uscomputergurus.com> wrote:
> > Thanks for joining the conversation.  I ran my the HTML page which was
> > generated by my .erb.  I had a form_for with an embedded div and the
> > HTML page had an embedded div.  W3C didn't like it.  The details are

> > athttp://www.pastie.org/881730.


>
> Read line 11 of your validation pastie -- that is almost certainly your
> problem.
>
> Getting used to reading the HTML DTD(s) would be a good idea :-)
>
> --

> Hassan Schroeder ------------------------ hassan.schroe...@gmail.com
> twitter: @hassan

Reply all
Reply to author
Forward
0 new messages