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

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 } %>



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

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:


18: <%= f.label :vendor %>

19: <%= f.text_field :vendor %>
20: <%= image_tag “DownArrow.jpg” options =
{ onclick=page[“vendor_droplist”].show } %>
21:

22:


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:innew’

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 } %>

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

    On Mar 21, 12:07 am, RichardOnRails

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 } %>

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

    On Mar 21, 12:07 am, RichardOnRails

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> ) %>


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

On Mar 21, 12:37 am, RichardOnRails

On 21 March 2010 04:07, RichardOnRails
[email protected] 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

On 21 March 2010 05:02, RichardOnRails
[email protected] 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

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

<%= f.label :vendor %>
<%= f.text_field :vendor %> <%= button_to_function("ShowList", % ) %>

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

Generated HTML

Vendor

<input id="expense_vendor" name="expense[vendor]" size="30"

type=“text” />



<div id=“vendor_droplist”, style=“display:none”>
IBM

Fed Ex

On 21 March 2010 10:49, RichardOnRails
[email protected] 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 Mon, Mar 22, 2010 at 1:35 PM, RichardOnRails
[email protected] wrote:

Your “how’s the HTML” question really did the job:

tag not allowed within the scope of a tag.

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


Hassan S. ------------------------ [email protected]
twitter: @hassan

Hey Colin,

Your “how’s the HTML” question really did the job:

tag not allowed within the scope of a tag.

Which means the my .erb can’t have:

<% form_for(@expense) do |f| %>
[snip]


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

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 L. [email protected] wrote:

shows up the reason why something is not working as you expect.

Colin

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 S. [email protected]

On 22 March 2010 21:51, RichardOnRails
[email protected] 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 with a nested

that the W3C is
complaining at, it’s that you have a

with a nested

- lines
33 and 39 of your NewExpensePage.htm

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 %>

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



<%= select_tag “list”,
options_for_select(@current_vendors),
:multiple => true, :size => 3 %>

<%# 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 P. [email protected] wrote:

It’s not that you have a with a nested

that the W3C is
complaining at, it’s that you have a

with a nested

- lines
33 and 39 of your NewExpensePage.htm

Hi Hassan, please take a look at my reply to Michael.

On Mar 22, 6:11 pm, Hassan S. [email protected]

On Mon, Mar 22, 2010 at 2:51 PM, RichardOnRails
[email protected] 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 :slight_smile:


Hassan S. ------------------------ [email protected]
twitter: @hassan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs