user16455
user16455

Reputation: 267

rails and prototype question

I am trying to use afterfinish callback to set focus on a text field after a prototype's Effect and I am not getting this javascript right.

Can someone help me?

<%= link_to_function "Enter Data" do |page |
      page.visual_effect :appear , 'section1', 
          :afterFinish => "document.getElementById('name').focus()"
    end %>

<div id="section1" style="display:none;">
         <%= label_tag 'Your Name' %>
        <%= text_field_tag 'name', '', :size => 20 %>
</div>

Upvotes: 0

Views: 111

Answers (2)

user16455
user16455

Reputation: 267

This is what works for me

page.visual_effect :appear, 'section1', :afterFinish => "function(){$('name').focus()}"

This is a limitation of rjs wherein you cannot insert prototype methods like Jordan suggests, Instead you have to put raw js.

Hope this helps someone.

Upvotes: 1

Jordan Running
Jordan Running

Reputation: 106077

If you want to use the Prototype method focus() you should do it like this:

<%= link_to_function "Enter Data" do |page |
      page.visual_effect :appear , 'section1', 
          :afterFinish => "Form.Element.focus('name')"
    end %>

Upvotes: 0

Related Questions