ruby on rails - I have 3 forms displayed by checkbox - How can I show only the form that is checked using jQuery? -
so making feed user can post link, text, or image. each posting uses own simple form. of can display each form checkbox, can't figure out how hide other forms when clicked.
<!-- ************************ text post ************************ --> <%= simple_form_for @tl_text |f| %> <div id="textpost" style=display:none class="hidden"> <%= f.text_area :content, label: "512 character limit", placeholder: "512 character limit", :rows => 6, :cols => 30 %> <%= f.submit "submit" %> </div> <input name="text" id="text_checkbox" type="checkbox" value="yes" />text <% end %> <!-- ************************ link post ************************ --> <%= simple_form_for @tl_link |f| %> <div id="linkpost" style=display:none class="hidden"> <%= f.input :link, label: "please enter link here" %> <%= f.text_area :content, :rows => 6, :cols => 30 %> <%= f.submit "submit" %> </div> <input name="link" id="link_checkbox" type="checkbox" value="yes" />link <% end %> <!-- ************************ image post ************************ --> <%= simple_form_for @tl_image |f| %> <div id="imagepost" style=display:none class="hidden"> <%= f.file_field :image %> <%= f.text_area :content, :rows => 6, :cols => 30 %> <%= f.submit "submit" %> </div> <input name="image" id="image_checkbox" type="checkbox" value="yes" />image <% end %> <script> $('input[type="checkbox"]').on('change', function () { $('#' + this.name + 'post').slidetoggle(this.checked) $(this).siblings('input').prop('checked', false); }); </script>
you try this
var $checkboxes = $('input[type="checkbox"]'); $checkboxes.on('change', function () { $checkboxes.each(function () { var $this = $(this), $form = $this.prev('div'); this.checked ? $form.slidedown('slow') : $form.slideup('slow'); }); });
Comments
Post a Comment