2012-10-03 31 views
16

Active Adminに編集フォームがあります。私は読書だけのフィールドが必要です。私はこれを行うことができますどのようにこのActive Adminの編集ページに値のみを表示する方法

enter image description here

のようなページを見て必要

enter image description here

よう

私の現在の編集ページです。編集フォームページのコードは、

form :html => { :enctype => "multipart/form-data" } do |f| 
     f.inputs "Users" do 
     f.input :device, :label => 'Device', :as => :select, :collection => DEVICE, :include_blank => false 
     f.input :current_address, :label => 'Current Address', :as => :string 
     end 
    end 

のようになります。

+0

この問題の進捗状況はありますか? – Fivell

+0

実際に何をしたのですか?disabled => true、無効なテキストボックスが表示されます。私はページの色と一致するようにテキストボックスの背景をスタイルしました。それで、私は必要なもののように見えます。しかし、それは正しい方法ではありません:( –

+0

それは残念です、私は追加するときに良いオプション – Fivell

答えて

2

住所入力フィールドに, :disabled => trueを追加してみてください。

+0

することができます:disabled => tureそこにテキストボックスを見ることができ、それは編集可能ではありません。 –

34

アレックスが言ったように、無効に設定しました。あなたは、そのセマンティクスで暮らすことができれば、あなたが望むビジュアルを得るためにCSSを使うことができます。

これを機能させるには構文が少し異なります。あなたの管理者フォームで

:あなたのActiveAdmin.register内クリーナーフォーム定義については

input[disabled="disabled"], 
input[disabled] { 
    background-color: #F4F4F4; 
    border: 0px solid #F4F4F4 !important; 
} 
+0

ヒントありがとうございました! –

+0

THXたくさん@私はCSSに小さな変更を加えて無効な "フィールド"のアイデアを強調しました: 'border:0px solid#F4F4F4!important;'を 'cursor: ' – microspino

9

active_admin.cssあなたのCSSで

f.input :finish_position, input_html: { disabled: true } 

{}あなたが同様に定義することもできますブロックアクティブな管理者で使用する "readonly"入力タイプ。formtasticを使用します。

フォームブロックの構文は、activeadminバージョン1.0.0.pre at 0becbef0918aです。

# app/admin/inputs/readonly_input.rb 

class ReadonlyInput < Formtastic::Inputs::StringInput 
    def to_html 
    input_wrapping do 
     label_html << 
     template.content_tag('div', @object.send(method)) 
    end 
    end 
end 

# app/admin/your_model.rb 

ActiveAdmin.register YourModel do 
    # ... 

    form do |f| 
    # ... 

    input :current_address, as: :readonly 

    # ... 
    end 
end 
+0

これは、フォームが送信されたときにコントローラに値を送信しますか? – harshitpthk

+0

理論上それはフィールドの既に保存された値を表示しているので、理由がわからない – Whatcould

2

私は同じ問題に直面して:disabledを使用してみましたが、私はそれをサーバーに送信中params対象に含まれることにfield値を望んでいたとして、それは私の問題を解決しなかったました。 form input:input_html => {:disabled => true}とマークすると、このフィールド値はparamsに含まれません。 ので、代わりに私は私の問題の両方を解決し:input_html => {:readonly => true}を使用:

  1. edit
  2. にユーザーを許可していない私はこれが役立つことを願っていますparams

の値が含まれています。

+0

' input_html => {:disabled => true} '、このフィールド値はparamsには含まれません –

0

"オブジェクト"を使用するのがトリックです。

form :html => { :enctype => "multipart/form-data" } do |f| 
    f.inputs "Users" do 
    f.input :device, :label => 'Device', :as => :select, :collection => DEVICE, :include_blank => false 
    f.label :current_address, f.object.current_address 
    end 
end 
0

これはどうですか?

form :html => { :enctype => "multipart/form-data" } do |f| 
    f.inputs "Users" do 
    f.input :device, :label => 'Device', :as => :select, :collection => DEVICE, :include_blank => false 
    f.li do 
     f.label :current_address 
     f.span f.object.current_address 
    end 
    end 
end 
関連する問題