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;”%>
<% end %>
review-dropdown = function(){
if(this.value == “Add New”) {
$(’.class-show’).show();
$(’.class-show’).val(’’);
}else{
$(’.class-show’).hide();
$(’.class-show’).val(this.value);
}
});