Home Rails Active Admin - how to set up a form's with a drop down that includes X choices plus a "free" input
Reply: 1

Rails Active Admin - how to set up a form's with a drop down that includes X choices plus a "free" input

Mathieu
1#
Mathieu Published in 2018-01-09 10:16:00Z

I would like to set up for an Active Admin form a field called field_example (string type), a basic dropdown that would show

  • option 1
  • option 2
  • option 3
  • freely inputed field

I would like to enable the user to choose of the 3 basic options but if he does not recognize himself in those 3 options, be able to type freely another string (this string would not have to be added to the list of options for future forms edition). He could type anything.

Is it possible?

My code today:

admin/model.rb

f.input :field_example,
        as:         :select,
        collection: LIST_OF_OPTIONS,
        prompt:     true

config/initializers/active_admin_constants

LIST_OF_OPTIONS = ["option1","option2", "option3"] 
Piers C
2#
Piers C Reply to 2018-01-10 19:41:12Z

There's nothing in ActiveAdmin (Formtastic) that helps you with that, but a popular option often used with ActiveAdmin is Select2, which might help, see for example Select 2 version 4.0 allow user to enter free text

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.309861 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO