Skip to main content

Autocomplete a form field

General • Asked by Benny Maas

Hi,

i have the following models:
users, markets, assignments, products, sales,

a user gets an assignment, and then he should enter his sales for the assignment.

i have a sales form with the following fields:

quantity, product, price

now i want to autocomplete the product_field with the products from the product model.
only products that are in the database, no new products should get over the sales form.

Any hint how to start this?

thanks


Benny,

Have you looked into collection_select? It will let you make a dropdown for the product_id on the sale form. It'll automatically load up all the Products in the database and create a dropdown for you.

Then you could do something like select2 (https://select2.github.io/examples.html) on that form field to make it do autocomplete.

https://github.com/argerim/select2-rails


Hi Chris,

thanks for your reply.
I will try your suggestion.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.