Commit 85bd43472dd428ee8ad449b9065e0fbfbb91dd82

Authored by Gabriela Navarro
Committed by Fabio Teixeira
1 parent 1a51c6d2

Transforming the city field in auto complete.

  - To use it, you first need to provide the state.

Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
public/views/create-institution.js
@@ -239,6 +239,7 @@ modulejs.define(&#39;CreateInstitution&#39;, [&#39;jquery&#39;, &#39;NoosferoRoot&#39;, &#39;SelectElement&#39;] @@ -239,6 +239,7 @@ modulejs.define(&#39;CreateInstitution&#39;, [&#39;jquery&#39;, &#39;NoosferoRoot&#39;, &#39;SelectElement&#39;]
239 cnpj.hide(); 239 cnpj.hide();
240 city.hide(); 240 city.hide();
241 state.hide(); 241 state.hide();
  242 + autocomplete_city();
242 } else { 243 } else {
243 cnpj.show(); 244 cnpj.show();
244 city.show(); 245 city.show();
@@ -246,11 +247,32 @@ modulejs.define(&#39;CreateInstitution&#39;, [&#39;jquery&#39;, &#39;NoosferoRoot&#39;, &#39;SelectElement&#39;] @@ -246,11 +247,32 @@ modulejs.define(&#39;CreateInstitution&#39;, [&#39;jquery&#39;, &#39;NoosferoRoot&#39;, &#39;SelectElement&#39;]
246 } 247 }
247 } 248 }
248 249
  250 + function autocomplete_city(){
  251 + $('#city_field').autocomplete({
  252 + source : function(request, response){
  253 + $.ajax({
  254 + type: "GET",
  255 + url: '/account/search_cities',
  256 + data: {city_name: request.term, state_name: $("#community_state").val()},
  257 + success: function(result){
  258 + response(result);
  259 + },
  260 + error: function(ajax, stat, errorThrown) {
  261 + console.log('Link not found : ' + errorThrown);
  262 + }
  263 + });
  264 + },
  265 +
  266 + minLength: 3
  267 + });
  268 + }
  269 +
249 270
250 function institution_type_actions(type) { 271 function institution_type_actions(type) {
251 var country = $("#community_country").val(); 272 var country = $("#community_country").val();
252 if( type === "PublicInstitution" && country == "BR") { 273 if( type === "PublicInstitution" && country == "BR") {
253 show_public_institutions_fields(); 274 show_public_institutions_fields();
  275 + autocomplete_city();
254 } else { 276 } else {
255 show_private_institutions_fields(); 277 show_private_institutions_fields();
256 } 278 }
views/gov_user_plugin/_institution.html.erb
@@ -68,7 +68,7 @@ @@ -68,7 +68,7 @@
68 </div> 68 </div>
69 </span> 69 </span>
70 70
71 - <%= required f.text_field(:city) %> 71 + <%= required f.text_field(:city, :id => "city_field") %>
72 72
73 73
74 <span class='required-field'> 74 <span class='required-field'>