Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide form until button is clicked - Ruby on Rails

I have a content submission form on the home page of my app.

I would like to have it be hidden until a user clicks "submit an idea", at which point, the form should appear below the submit button.

I'm basing this off of the model used for replies/comments on Reddit, but I can't quite figure it out.

I'd imagine it involves jQuery, but I am terrible with jQuery, which is why I need your help.

Thanks a lot in advance.

like image 245
Steve Thomas Avatar asked May 12 '26 22:05

Steve Thomas


2 Answers

You can do it with jQuery.

 $(document).ready(function() {

 $('#form_id').hide(); //Initially form wil be hidden.

  $('#button_id').click(function() {
   $('#form_id').show();//Form shows on button click

   });
 });
like image 198
samir chauhan Avatar answered May 15 '26 14:05

samir chauhan


Hide the form when the page loads:

$('#my-form').hide();

and show it when a button is clicked:

$('#my-button').click(function() { $('#my-form').show() });
like image 35
meagar Avatar answered May 15 '26 15:05

meagar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!