A little plugin containing a form builder that uses css to produce tableless, lined-up forms.
一個(gè)包含用CSS來(lái)產(chǎn)生無(wú)表格、直排表單的表單生成器的小插件
功能
- 每個(gè)field label自動(dòng)加到該input control的上方
- 每個(gè)input control 出現(xiàn)在最近c(diǎn)ontrol的右方(除非沒(méi)有空間)
- 要強(qiáng)制把control放在新行,用
- 用{:class=>'half-size' } or {:class=>'double-size' }等這些html選項(xiàng)來(lái)改變control大小
- 用 class 'half-size', 'normal-size' or 'double-size' 勒令 select tags大小
- 用<% fieldset tag 'legend' %> [block] <% end %>來(lái)生成fieldset tags
- 作為默認(rèn),一個(gè)fieldset 擴(kuò)充到右對(duì)齊;用html option{:class=>’continue’}來(lái)壓縮fieldset,下一個(gè)fieldset將加在右邊
- 支持用_()來(lái)對(duì)lables 和legens進(jìn)行翻譯(是通過(guò)首先calling CssBuilder.translate_as_gettext)(其實(shí)是在custom_envoirnment.rb中就call了); 或用String.t(by first calling CssBuilder.translate_as_globalize)
- 支持標(biāo)準(zhǔn)html form(css_form_for)和遠(yuǎn)程form(remote_css_form_for)
- 也包含一個(gè)show_builer(css_show_for),能用和同樣的template file(如_form.rhtml)視它看起來(lái)和new/edit 的form一樣,其中的field values 已經(jīng)用html text 顯示,而不用form和input control
example:
File app/views/customers/edit.rhtml:
<% css_form_for :customer, @customer, :url => { :action => 'update', :id => @customer } do |@f| %>
<%= render :partial=> 'form' %>
<%= submit_tag 'Edit' %>
<% end %>
File app/views/customers/show.rhtml:
<% css_show_for :customer, @customer, do |@f| %>
<%= render :partial=> 'form' %>
<% end %>
另外還增加了
module ActionView::Helpers :: FormOptionsHelper #select_with_choises(object, method, choices, options = {}, html_options = {}) 這個(gè)select 支持choice
實(shí)際上是自制表單構(gòu)建器:
CssShowBuilder : css_show_builder.rb 這個(gè)挺有意思的
CssFormBuilder: css_form_builder.rb
加上一些helper
css_form_support.rb
如對(duì)本文有疑問(wèn),請(qǐng)?zhí)峤坏浇涣髡搲瑥V大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇