Reputation: 77
My problem is that when i fill out this form and submit. It always submits Origin_Radius as empty when i am on origin_city_search div
My hypothisis on the issue is that since i have 2 of the same fields named the same (Origin_Radius) is that it is always taking the value of the last one. in the below form it is the one in the origin_zip_search DIV... witch that radius form works... just not the one in the origin_city_search DIV.
any pointers on how to get this to submit Origin_Radius on each of the divs would be great.
HTML
<form accept-charset="UTF-8" action="/searches" id="search_form" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="KXseapxrgZ3SwnhQZNAG+D0RD+/ydVxAXFQ2OkyaDb4=" /></div>
<input id="search_user_id" name="search[user_id]" type="hidden" value="10181" />
<div class='control-group'>
<label class="control-label" for="origin_cs_Origin">Origin</label>
<div class='controls'>
<div id='origin_city_search' style='display:block;'>
<input autocomplete="true" class="appendedInput span7" data-autocomplete-internal="true" id="search_origin_cs" name="search[origin_cs]" placeholder="City, ST" style="z-index:3;" type="text" value="" />
<input class="appendedInput span3" id="search_origin_radius" name="search[origin_radius]" placeholder="Radius" type="text" value="" />
</div>
<div id='origin_zip_search' style='display:none;'>
<input class="span7" id="search_origin_zip" name="search[origin_zip]" placeholder="Zipcode" type="text" value="" />
<input class="appendedInput span3" id="search_origin_radius" name="search[origin_radius]" placeholder="Radius" type="text" value="" />
</div>
<div id='origin_state_search'>
<input class="span10" data-states="" id="search_origin_states" name="search[origin_states]" placeholder="Enter Multiple States" style="display:none;" type="text" value="" />
</div>
<div class='btn-group'>
<a class='active btn' href='javascript:void()' id='origin_city_search_boolean'>City Search</a>
<a class='btn' href='javascript:void()' id='origin_state_search_boolean'>State Search</a>
<a class='btn' href='javascript:void()' id='origin_zip_search_boolean'>Zip Search</a>
</div>
</div>
</div>
View:
.control-group
=label :origin_cs, "Origin", {:class => "control-label"}
.controls
-(zip_display = "none";state_display = "none";city_display = "block";city_active ="active";state_active="";zip_active = "") if search.origin_states.blank? and search.origin_zip.blank?
-(zip_display = "none";state_display = "block";city_display = "none";state_active = "active";city_active="";zip_active = "") unless search.origin_states.blank? and search.origin_zip.blank?
-(zip_display = "block";state_display = "none";city_display = "none";zip_active = "active";state_active = "";city_active="") unless search.origin_states.blank? and search.origin_cs.blank?
#origin_city_search{style: "display:#{city_display};"}
=text_field_tag "search[origin_cs]", "", {:placeholder =>ADDRESSHOLDER, :class => "appendedInput span7", style: "z-index:3;", autocomplete: "true", "data-autocomplete-internal" => "true"}
=text_field_tag "search[origin_radius]","", {:placeholder =>"Radius", :class => "appendedInput span3"}
#origin_zip_search{style: "display:#{zip_display};"}
=text_field_tag "search[origin_zip]", "", {:placeholder => "Zipcode", class: 'span7'}
=text_field_tag "search[origin_radius]","", {:placeholder =>"Radius", :class => "appendedInput span3"}
#origin_state_search
=text_field_tag "search[origin_states]", "", {placeholder: "Enter Multiple States", class: 'span10', "data-states" => states_searched(search.origin_states), style: "display:#{state_display};"}
.btn-group
%a.btn{href: "javascript:void()", id: "origin_city_search_boolean", class: "#{city_active}"} City Search
%a.btn{href: "javascript:void()", id: "origin_state_search_boolean", class: "#{state_active}"} State Search
%a.btn{href: "javascript:void()", id: "origin_zip_search_boolean", class: "#{zip_active}"} Zip Search
Javascript
$(document).on "click", "#origin_state_search_boolean", ->
$(this).addClass("active")
$('#origin_city_search_boolean').removeClass("active")
$("#origin_city_search").hide()
$("#origin_city_search input").each ->
$(this).val("")
$('#origin_zip_search_boolean').removeClass("active")
$("#origin_zip_search").hide()
$("#origin_zip_search input").each ->
$(this).val("")
$("#origin_state_search").show()
unless $('#origin_state_search .token-input-list-facebook').length
$("#search_origin_states").tokenInput("/searches/states.json", theme: "facebook", prePopulate: $.parseJSON($('#search_origin_states').attr("data-states")), placeHolderText: "Enter States Here")
$(document).on "click", "#origin_zip_search_boolean", ->
$(this).addClass("active")
$('#origin_city_search_boolean').removeClass("active")
$("#origin_city_search").hide()
$("#origin_city_search input").each ->
$(this).val("")
$('#origin_state_search_boolean').removeClass("active")
$("#origin_state_search").hide()
$("#origin_state_search input").each ->
$(this).val("")
$("#origin_zip_search").show()
$(document).on "click", "#origin_city_search_boolean", ->
$(this).addClass("active")
$('#origin_state_search_boolean').removeClass("active")
$("#origin_city_search").show()
$("#search_origin_states").val("")
$("#origin_state_search .token-input-token-facebook").remove()
$("#origin_state_search").hide()
$('#origin_zip_search_boolean').removeClass("active")
$("#origin_zip_search").hide()
$("#search_origin_zip").val("")
Upvotes: 0
Views: 134
Reputation: 15838
use different names for each field, you can't have 2 fields with the same name, use something like "origin_radius_cs" and "origin_radius_zip"
Upvotes: 1