2011-09-15 6 views
0

これがなぜ機能しないのかわかりません - または - 何か重要なものがありませんか?ここでSimpleFormでいくつかの(テキスト、ブーリアン、...)タイプのカスタム入力を作成できません

がsimple_form / lib/simple_form/form_builder.rbからマッピングされたタイプのリストです:

map_type :text,        :to => SimpleForm::Inputs::TextInput 
map_type :file,        :to => SimpleForm::Inputs::FileInput 
map_type :string, :email, :search, :tel, :url, :to => SimpleForm::Inputs::StringInput 
map_type :password,       :to => SimpleForm::Inputs::PasswordInput 
map_type :integer, :decimal, :float,   :to => SimpleForm::Inputs::NumericInput 
map_type :range,        :to => SimpleForm::Inputs::RangeInput 
map_type :select, :radio, :check_boxes,  :to => SimpleForm::Inputs::CollectionInput 
map_type :date, :time, :datetime,    :to => SimpleForm::Inputs::DateTimeInput 
map_type :country, :time_zone,     :to => SimpleForm::Inputs::PriorityInput 
map_type :boolean,        :to => SimpleForm::Inputs::BooleanInput 

まず問題、私のようにStringInputクラスを拡張することができます

#app/inputs/string_input.rb 
class StringInput < SimpleForm::Inputs::StringInput 
    def input 
    if @builder.show? 
     content_tag(:p, @builder.object[attribute_name], :class => :show) 
    else 
     super 
    end 
    end 
end 

(私はビルダーを拡張しましたショー?コンテキストを検出する方法:アクション== 'show')

これは、ほとんどの時間を働いているが、:as => :stringが存在しないとき:

<%= f.input :estimated_duration_rendered, 
    :as => :string, 
    :label => mt(:estimated_duration), 
    :hint => mt(:estimated_duration_hint), 
    :error => false, 
    :required => false, 
    :input_html => { :class => :digits_11, :placeholder => mt(:estimated_duration_placeholder), :value => format_duration(resource.estimated_duration, true) } 
%> 

第二の問題は、私はStringInput、DateTimeInput、CollectionInputとBooleanInputのカスタム入力を作成することができますが、他のすべてが動作していません。たとえば:

#app/inputs/text_input.rb 
class TextInput < SimpleForm::Inputs::TextInput 
    def input 
    if @builder.show? 
     "I will never show..." 
    else 
     super 
    end 
    end 
end 

は、私は私の形で、このヘルパーを持っている場合でも:もちろん

<%= f.input :description, 
      :label => mt(:description), 
      :hint => mt(:description_hint, :max => MyModel::DESC_MAX_LENGTH), 
      :input_html => { :class => :large, :rows => 8, :cols => 1, :maxlength => MyModel::DESC_MAX_LENGTH, :placeholder => mt(:description_placeholder) }, 
      :error => false 
%> 

を、説明はテキストデータ型を持っています。

私は間違っていますか?

ありがとうございます。

あちこち

答えて

2

さて、あなただけのSimpleFormの1.5.1バージョンを必要とし、この機能を使用します。 :-)

関連する問題