2015-09-28 20 views
-1

我有一個漂亮的,bootstrappy形式,看起來像(在軌& HTML)製作span元素提交編輯表單

<%= form_for(current_user) do |f| %> 
    <div class="input-group input-group-lg"> 
    <%= f.text_field :location, :class => "form-control", :placeholder => "Where are you?", 'aria-describedby' => 'basic-addon2' %> 
    <span type="submit" name="commit" class="input-group-addon btn btn-success" id="basic-addon2" style="color: white;">Go!</span> 
    </div> 
<% end %> 

但使用上述,沒事的時候我打的實際情況「走!」按鈕。

我可以讓我的形式成功地提交,如果我使用的代碼:

<%= form_for(current_user) do |f| %> 
    <div class="input-group input-group-lg"> 
    <%= f.text_field :location, :class => "form-control", :placeholder => "Where are you?", 'aria-describedby' => 'basic-addon2' %> 
    <%= f.submit "Go!", class: "input-group-addon btn btn-success", id: "basic-addon2", style: "color: white;" %> 
    </div> 
<% end %> 

我的問題是,我無法合併兩個版本,即保留前者的美觀,同時增加功能的後者。我嘗試過的所有方法都跨越了跨度或其他奇怪組合中的按鈕或按鈕,但沒有任何設法可以做到我想要的。我可以使<span><button>(由f.submit生成)的屬性完全相同,我的瀏覽器所看到的HTML的唯一區別是一個是<span>,另一個是<button>

任何人都可以想出一種方法來合併這兩個概念嗎?

+0

'span'沒有'type'或'name'屬性。你不能只是交換HTML元素,並期望它們具有相同的功能......如果它是某種_visual look_,那麼你應該使用適當的元素,然後通過CSS使用_format_。 – CBroe

回答

0

你看到你不能使用鏈接跨度或其他東西,導致這個提交按鈕作爲post方法通過瀏覽器。而鏈接進入獲取方法。但對於任何元素爲提交按鈕,只需按照該指令工作的解決方案.. Submit Rails 4 form with link instead of button

+0

如果這是一個騙局,然後標記爲與欺騙鏈接的一個騙局。 –

+0

不,不,沒關係......對不起。 –

+0

不用擔心;只是令人困惑:) –

0

當您單擊span標籤您可以隨時觸發submit事件:

# Inside your document.ready function in your .js file 

$('#my_span').on('click', function() { 
    $('#my_form').submit(); 
}); 

哈克的方式,但它的工作原理。

+0

這不是哈克,這就是你如何做到這一點。 –