views:

1374

answers:

1

HI I tried using a javascript function call in the submit tag of a form_remote_for but it is not able to find the function im calling. if i call the same function from form_remote_for then ajax stops working. can ny one help me how can i call an javascript function when im using form_remote_for NOT FORM_REMOTE_TAG....????

+1  A: 

I think REMOTE_FORM_FOR is what you need.

example:

In your view:

<%- remote_form_for(comment, :url => topic_post_comments_path(@topic, post), 
           :after => "submitComment(self);$('input').disable()") do |f| %>
<%= f.text_field :body, :size => 70, :class => "comment_body" %><br />
<%= f.submit "Submit", :class => "comment_submit" %>
<%- end -%>

Notice: the javascript function in :after is my custom javascript functions.

And in your controller (it's comments_controller here)

@comment = @post.comments.new params[:comment] # actually, it depends on your model :p

respond_to do |format|
  # remember to handle exception here. like if @comment.save or not
  format.html
  format.js { 
    render :update do |page|
      pagepage.visual_effect :highlight, "comments"
    end
  }
end

anyway it's just a easy sample, you have to handle more details after you get some feeling for remote_form_for.

Good luck.

Yi-Ru Lin