Ask A Question

Notifications

You’re not receiving notifications from this thread.

Autocomplete a form field

Benny Maas asked in General

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

Reply

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

Reply

Hi Chris,

thanks for your reply.
I will try your suggestion.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,536+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.