Gagan Gami
Gagan Gami

Reputation: 10251

How to override text field to textarea in rails_admin

First time I try to customize rails_admin and by default I am getting text field which I want to convert in textarea. In model I have given datatype as string So is that possible to display textarea?

config/initializer/rails_admin.rb

config.model Product do
    list do
      exclude_fields :id, :created_at, :updated_at
    end
    create do
     ......
     configure :description do
        partial 'my_partial_file' # to override field I have created partial file
      end
     .....
    end

  end

views/rails_admin/main/_my_partial_file.html.haml

= form.send field.view_helper, field.method_name, field.html_attributes.reverse_merge({ value: field.form_value, checked: field.form_value.in?([true, '1']), class: 'form-control', required: field.required})

I tried html_attributes rows: 50, cols: 60 also tried to apply custom_css but doesn't help. Please guide me where I do mistake? And if possible please make me understand syntax of this _my_partial_file

Edit: If I do something like this then I can get textarea

field :description, :text do # use second parameter to set field type
  required true        
  #partial 'my_partial_file'
end

But if I render partial then again text_field shown. :( I want text_area + partial file should also rendered as it contain other code to process.

Upvotes: 2

Views: 2000

Answers (1)

Gagan Gami
Gagan Gami

Reputation: 10251

I have solved this issue by my own. I thought to delete this question but then realized if in future anyone faced same issue then my solution can be helped.

What I had changed in _my_partial_file is:

= form.text_area field.method_name, field.html_attributes.reverse_merge({ value: field.form_value, checked: field.form_value.in?([true, '1']), class: 'form-control', required: field.required})
........ # other piece of code

and in config/initializer/rails_admin.rb I have keep the code as it is:

   create do
     ......
     configure :description do
        partial 'my_partial_file' 
      end
     .....
    end

I got the reference from here: https://www.omniref.com/ruby/gems/obitum-rails_admin/0.0.5/files/app/views/rails_admin/main/_form_text.html.haml#line=5 (Wayback link)

and

http://ruby-doc.org/gems/docs/r/rails_admin_settings-0.8.0/app/views/rails_admin/main/_setting_value_html_haml.html

(Note: link dead. This may be the same file from that older version: https://github.com/rails-admin/rails_admin_settings/blob/v0.8.0/app/views/rails_admin/main/_setting_value.html.haml )

Upvotes: 3

Related Questions