0
我正在使用simple_forms gem爲我的模型創建表單。簡單表單輸入字段爲純文本不可手動編輯
模型包含一些字段,這些字段是基於其他字段的javascript計算的結果,所以我希望將它們表示爲文本而不是輸入字段,以圖形方式顯示它們不可編輯,不要混淆人。
這裏是我迄今爲止在我看來:
- field = "time_quantity"
%strong{:id => "#{field}_str", :class => "text-success"}
= f.object[field]
= f.input field, as: :hidden, input_html: {value: f.object[field]}
在%strong
文字寫入值作爲文本,隨後輸入字段就是插入與形式的模型。
此外,與此問題是,如果我輸入這些領域的錯誤數據,我不會看到他們旁邊的任何錯誤通知,因爲它將被隱藏。如圖所示:
<strong class="text-success" id="time_quantity_str" data-original-title="" title=""></strong>
<div class="input hidden project_time_quantity field_with_errors">
<input class="hidden input-medium" id="project_time_quantity" name="project[time_quantity]" type="hidden">
<span class="error">can't be blank</span>
</div>
我想改變這類似:
- field = "time_quantity"
%strong{:id => "#{field}_str", :class => "text-success"}
= f.input field, as: :plain, input_html: {value: f.object[field]}
有更多DRY在視圖中,在JavaScript。
您認爲可以做到這一點?
感謝,
謝謝,第一個選項有點解決它,雖然圖形不是我正在尋找。也許我可以改變輸入字段的外觀和感覺,看起來像一個標籤?你會知道如何通過bootstrap獲得這個嗎? –