Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set :maxlength in ActiveAdmin panel, Rails 4

Problem: I would like to limit input characters for description field. I have done similar function to phone number, but I can't do the same for description field.

My code:

This code works:

  f.input :phone_number, :input_html => { :class => 'autogrow', :rows => 1, :cols => 2, :maxlength => 8 }

This code doesn't work:

f.input :description, :input_html => {:class => 'autogrow', :rows => 10, :cols => 10, :maxlength => 200  }
f.input :description_ru, :input_html => {:class => 'autogrow', :rows => 10, :cols => 10, :maxlength => 200  }

Maybe maxlength works just for string type fields ? Because maxlength works for phone number (string datatype) and doesn't work for description and description_ru (both are text datatype in database).

Thank you in advance!

like image 436
Edgars Avatar asked Oct 14 '25 18:10

Edgars


1 Answers

Yes, I think you're right that it works just for string type fields.

This seems to work:

f.input :myfield, as: :string, input_html: { maxlength: 50 }

I just had this problem with a :text field, switching to :string solved the issue for me.

like image 185
Simone Avatar answered Oct 17 '25 07:10

Simone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!