javascript - How to add a button to a partial which closes the partial? -


i have partial

_reply.haml

.reply-form     = form_for comment, :remote => true |f|         = f.text_area :body, :input_html => { :rows => "2" }, :label => false         = f.text_field :commentable_id, :as => :hidden, :value => comment.commentable_id         = f.text_field :commentable_type, :as => :hidden, :value => comment.commentable_type         = f.text_field :p_comment, :as => :hidden, :value => parent_comment.id         = f.submit "reply!", :class => "btn btn-primary", :disable_with => "submitting…" 

i need add 'cancel' button remove partial page (hide , remove). _reply.haml partial not loaded when page loads. loads when clicks "reply" on comment.

i tried adding = button_tag 'cancel', :id => "cancel_button", :remote => true end of _reply.haml ended going through create action of comments controller reason. (if click reply, go create action of comments controller - correct).

actually need remove reply form can done using simple js code adding:

= button_tag 'cancel', :id => "cancel_button" 

as added above, remove div dom don't need send ajax request. can add js code:

$("#cancel_button").click(function(){   $(".reply-form").remove(); }); 

so when click again on reply ajax fired , partial loaded again in dom.

hope helps.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -