1
A
回答
2
作爲一個快速黑客用生命來繼續前進,添加此應用助手的底部作品簡單包裹在一個div每個標籤/輸入對:
module SimpleForm::ActionViewExtensions::Builder
def collection_radio(attribute, collection, value_method, text_method, options={}, html_options={})
collection.map do |item|
value = item.send value_method
text = item.send text_method
default_html_options = default_html_options_for_collection(item, value, options, html_options)
@template.content_tag(:div, radio_button(attribute, value, default_html_options) <<
label("#{attribute}_#{value}", text, :class => "collection_radio"))
end.join.html_safe
end
def collection_check_boxes(attribute, collection, value_method, text_method, options={}, html_options={})
collection.map do |item|
value = item.send value_method
text = item.send text_method
default_html_options = default_html_options_for_collection(item, value, options, html_options)
default_html_options[:multiple] = true
@template.content_tag(:div,
check_box(attribute, default_html_options, value, '') <<
label("#{attribute}_#{value}", text, :class => "collection_check_boxes"))
end.join.html_safe
end
end
2
它更乾淨,更好的方式來重新定義像下面輸入:
創建新目錄 '應用程序/輸入',
在其中創建文件 'collection_radio_buttons_input.rb',粘貼以下
class CollectionRadioButtonsInput < SimpleForm::Inputs::CollectionRadioButtonsInput
def item_wrapper_class
"radiobox"
end
def build_nested_boolean_style_item_tag(collection_builder)
collection_builder.radio_button + template.content_tag(:span,collection_builder.text)
end
end
打開選項 'config.inputs_discovery' 在配置/初始化/ simple_form.rb
瞧!
現在,這個控件將被用來代替默認RadioButtons的simple_form控件,並且您可以自由使用任何格式。
0
我剛剛用CSS做了。我在按鈕和標籤周圍用class =「radio-buttons」打了一個div。然後我說這我的樣式表(SASS):
.radio-buttons {
margin: .5em 0;
span input {
float: left;
margin-right: .25em;
margin-top: -.25em;
}
#this grabs the MAIN label only for my radio buttons
#since the data type for the table column is string--yours may be different
label.string {
margin-bottom: .5em !important;
}
clear: both;
}
.form-block {
clear: both;
margin-top: .5em;
}
.radio-buttons span {
clear: both;
display:block;
}
這將使單選按鈕內嵌在所有的框架,雖然這被調整到最好看的Zurb基金會。 ;)
相關問題
- 1. 單選按鈕/複選框
- 2. 個人simple_form單選按鈕
- 3. simple_form收集單選按鈕
- 4. 樣式複選框和單選按鈕
- 5. 單選按鈕和複選框javascript
- 6. jquery複選框和單選按鈕
- 7. 複選框和單選按鈕。值
- 8. 與複選框和單選按鈕
- 9. 單選按鈕和條件複選框
- 10. 複選框和單選按鈕圖像
- 11. Laravel 5.1單選按鈕和複選框
- 12. 造型複選框和單選按鈕
- 13. 切換複選框和單選按鈕選擇使用JavaScript?
- 14. Django表單複選框,單選按鈕
- 15. 如何使iphone中的單選按鈕和複選框按鈕?
- 16. 驗證行爲與複選框和單選按鈕
- 17. 複選框和單選按鈕的行爲
- 18. AngularJS選擇和取消選擇複選框/單選按鈕
- 19. jQuery - 複選框像單選按鈕
- 20. Javascript +單選按鈕/複選框驗證
- 21. 自定義複選框/單選按鈕
- 22. 單選按鈕+複選框組合
- 23. iAd Producer複選框單選按鈕?
- 24. 複選框來控制單選按鈕
- 25. 將單選框中的複選框(多選)轉換爲單選按鈕或複選框?
- 26. 更改複選框和單選按鈕的邊框顏色
- 27. 列表框與單選按鈕和複選框都在一個
- 28. 查找所有選中的複選框和單選按鈕
- 29. 基於單選按鈕和複選框的表單重定向?
- 30. 提交表單後保持單選按鈕和複選框(webMathematica)
謝謝,發現它在Sven Fuchs的叉子裏 – astropanic 2010-11-02 13:23:36