我的Rails地址选择器(address_picker-rails)可以使用第一个输入,但不是第二个输入?

时间:2013-03-18 09:23:53

标签: jquery ruby-on-rails jquery-ui geolocation

我正在使用address_picker-rails gem,它适用于第一个输入,但出于某种原因不是第二个输入。我现在经历了一百万次。有什么想法吗?

下面的_new表单代码与Jquery:

  <%= form_for(@post) do |f| %>
  <% if @post.errors.any? %>
  <div id="error_explanation">
  <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being      
   saved:</h2>

  <ul>
  <% @post.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
 </div>
 <% end %>
<fieldset>
 <div class="field">
  <%= f.label :from %><br />
 <%= f.text_field :from, :class => 'address-picker-input' %>
</div>
 </fieldset>
<fieldset>
<div class="field">
 <%= f.label :to %><br />
 <%= f.text_field :to, :class => 'address-picker-input' %>

</div>
</fieldset>

<script type="text/javascript">

    //AddressPickerRails.Pickers.applyOnReady({
    //    'onLoad':function (railsPicker) {
    //        console.debug("callback for a single post with ID '%s'",   
           railsPicker.getIdPrefix());
    //    }
    //});

    AddressPickerRails.Pickers.apply({
        'onLoad':function (railsPicker) {
            console.debug("callback for a single post with ID '%s'", 
             railsPicker.getIdPrefix());
        }
    });
</script>


 <div class="actions">
 <%= f.submit %>
 </div>
 <% end %>

HTML CODE:

<div class="field">
<label for="post_to">To</label><br>
<input class="address-picker-input ui-autocomplete-input" id="post_to" name="post[to]"   
size="30" type="text" autocomplete="off"><span role="status" aria-live="polite"   
class="ui-helper-hidden-accessible">19 results are available, use up and down arrow 
keys to navigate.</span>
</div>


<div class="field">
<label for="post_from">From</label><br>
<input class="address-picker-input" id="from_field" name="post[from]" size="30" 
type="text">
</div>

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

您需要为每个地址字段添加地图元素:

<div id="post_to_map_wrapper" class="address-picker-map-wrapper">
  <div id="post_to_map" class="address-picker-map"></div>
</div>

<div id="post_from_map_wrapper" class="address-picker-map-wrapper">
  <div id="post_from_map" class="address-picker-map"></div>
</div>

新的0.3.0版修复了这个问题!

答案 1 :(得分:0)

检查dom并确保这两个字段具有不同的dom ID。另外,您是否在控制台中看到任何javascript错误或调试输出?

<强>更新 要明确设置id(以保证唯一性)而不是让轨道猜测:

<%= f.text_field :from, :class => 'address-picker-input', :id => 'from_field' %>