Forum: Ruby on Rails observe_field :function show hide doesnt work

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F9bdba6e1c8a28664e99e9c8caaa05bd?d=identicon&s=25 Ami (Guest)
on 2008-11-09 00:53
(Received via mailing list)
<script>
function show_custom_repeat(){
    // var val = $('event_template_freq').getVal();
    // switch(parseInt(val)){
    //  case 5:
      $('custom_repeat').show();
    //  break;
  //  }
};
</script>

 Repeat: <%= select(:event_template, :freq, {:None => "0", :Daily =>
"1", :Weekly => "2", :Monthly => "3", :Yearly => "4", :custom =>
"5" }, {:selected => :None}) %>


<% observe_field("event_template_freq", :function =>
'show_custom_repeat') %>

<div id="custom_repeat" style="display: none;">

</div>


i use fire bug and no errors, i'm sure its just my syntax can anyone
help?
Ami
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-11-09 03:10
(Received via mailing list)
On Nov 8, 11:52 pm, Ami <Ami.mahl...@gmail.com> wrote:
>
>  Repeat: <%= select(:event_template, :freq, {:None => "0", :Daily =>
> "1", :Weekly => "2", :Monthly => "3", :Yearly => "4", :custom =>
> "5" }, {:selected => :None}) %>
>
> <% observe_field("event_template_freq", :function =>
> 'show_custom_repeat') %>
>
2 things:
- That needs to be <%=
observe_field just returns the appropriate javascript statement so if
you use <% then that javascript is never inserted into the view.
- while the statement show_custom_repeat is legal javascript, it is a
statement with no effect, it just evaluates to the function object (in
the same way that in ruby the expression "Object" is perfectly legal
but doesn't do an awful lot). If you want to call your function you
need show_custom_repeat() instead of show_custom_repeat

Fred
This topic is locked and can not be replied to.