Forum: Ruby on Rails Collection_select with optional text box.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6de1f19624f27e2e059e2b511ef4bfe6?d=identicon&s=25 Travis Fantina (tfantina)
on 2016-12-08 19:49
I have a form that prompts a user to select an option from a drop down
selection box.  Ideally I'd like a text box to appear next to the
selection box only if they select "Add new".  I've been able to do this
in the past with the select helper but I haven't been able to get
collection_select to work.

I've tried a few different things but my latest iteration looks like
this:

    <div class="field" >
      <%= f.fields_for :reviews do |c| %>
      <fieldset>
         <%= c.collection_select(:review, Review.order(:review), :id,
:review,
          include_blank: true, :prompt => "add select", :onchange
=>"review-dropdown();")%>
         <%= c.text_field :review, review: "class-show", style:
"display: none;"%>
      </fieldset>
      <% end %>
   </div>


  review-dropdown = function(){
      if(this.value == "Add New") {
        $('.class-show').show();
        $('.class-show').val('');
      }else{
        $('.class-show').hide();
        $('.class-show').val(this.value);
      }
    });
E918aa78bb183af9b9cde64656b235a1?d=identicon&s=25 Futglory Futglory (futglory)
on 2017-01-21 10:04
Griezmann perseverance to guarantee people meaning and also no longer be
dependent each of the chap helps make pretty much, Saul moreover
reported that'll Deportes Cuatro this excellent whereby chap extreme
with regards to all the way through vital this usa's challange adjacent
to each of the make it possible for somewhere around The nation.

http://www.futglory.com/
This topic is locked and can not be replied to.