Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 38121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:39:29+00:00 2026-05-10T14:39:29+00:00

I want to have a text box that the user can type in that

  • 0

I want to have a text box that the user can type in that shows an Ajax-populated list of my model’s names, and then when the user selects one I want the HTML to save the model’s ID, and use that when the form is submitted.

I’ve been poking at the auto_complete plugin that got excised in Rails 2, but it seems to have no inkling that this might be useful. There’s a Railscast episode that covers using that plugin, but it doesn’t touch on this topic. The comments point out that it could be an issue, and point to model_auto_completer as a possible solution, which seems to work if the viewed items are simple strings, but the inserted text includes lots of junk spaces if (as I would like to do) you include a picture into the list items, despite what the documentation says.

I could probably hack model_auto_completer into shape, and I may still end up doing so, but I am eager to find out if there are better options out there.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:39:29+00:00Added an answer on May 10, 2026 at 2:39 pm

    I’ve got a hackneyed fix for the junk spaces from the image. I added a :after_update_element => 'trimSelectedItem' to the options hash of the model_auto_completer (that’s the first hash of the three given). My trimSelectedItem then finds the appropriate sub-element and uses the contents of that for the element value:

    function trimSelectedItem(element, value, hiddenField, modelID) {     var span = value.down('span.display-text')     console.log(span)     var text = span.innerText || span.textContent     console.log(text)     element.value = text } 

    However, this then runs afoul of the :allow_free_text option, which by default changes the text back as soon as the text box loses focus if the text inside is not a ‘valid’ item from the list. So I had to turn that off, too, by passing :allow_free_text => true into the options hash (again, the first hash). I’d really rather it remained on, though.

    So my current call to create the autocompleter is:

    <%= model_auto_completer(     'line_items_info[][name]', '',      'line_items_info[][id]', '',     {:url => formatted_products_path(:js),      :after_update_element => 'trimSelectedItem',      :allow_free_text => true},     {:class => 'product-selector'},     {:method => 'GET',  :param_name => 'q'}) %> 

    And the products/index.js.erb is:

     <ul class='products'>     <%- for product in @products -%>     <li id='<%= dom_id(product) %>'>             <%= image_tag image_product_path(product), :alt => '' %>             <span class='display-text'><%=h product.name %></span>     </li>     <%- end -%>  </ul> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox that a user can type some text into. The area
I want to have a small text box with a scroll bar that will
I have a search field, and using that single text box I want the
I have a text box that I am the user enters a Supplier Name
I have a check box, RequiredFieldValidator and textbox that have editmask extender I want
I have a text-box, and I want to enter a string in language A
I have a text box on a web page, whose value I want to
i have a text box on my form. I want to write 0x31 as
I want to be able to have a text box on a page where
I have a text input field like text box or text area. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.