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 7665941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:42:27+00:00 2026-05-31T14:42:27+00:00

How do I integrate a typeahead from bootstrap like this: <input type=text class=span3 style=margin:

  • 0

How do I integrate a typeahead from bootstrap like this:

<input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="8" data-source='["University of Pennsylvania","Harvard","Yale","Princeton","Cornell","Brown","Columbia","Dartmouth"]'>

into a standard form like this:

<%= semantic_form_for(@education) do |f| %>
 <%= render 'shared/error_messages', object: f.object %>
<div class="field">
 <%= f.input :college, placeholder: "Update Education" %>
</div>
<%= f.submit "Submit", class: "btn btn-large btn-primary" %>
<% end %> 
  • 1 1 Answer
  • 0 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. Editorial Team
    Editorial Team
    2026-05-31T14:42:28+00:00Added an answer on May 31, 2026 at 2:42 pm

    In your controller

    def index
      @autocomplete_items = Model.all
    end
    

    In your view, just like you have with an additional ID for the selector…

    <% semantic_form_for(@education) do |f| %>
      <%= render 'shared/error_messages', object: f.object %>
      <div class="field">
        <%= f.input :college, placeholder: "Update Education", id: "auto_complete" %>
      </div>
      <%= f.submit "Submit", class: "btn btn-large btn-primary" %>
    <% end %> 
    

    And most importantly, pass the @autocomplete_items instance variable defined in your controller into a Javascript variable in your view:

    <%= javascript_tag "var autocomplete_items = #{ @autocomplete_items.to_json };" %>
    

    This will serialize your data and make it usable JSON for the Typeahead function to use.

    As for the Typeahead, simply pass that object (@autocomplete_items) as JSON to the Javascript like so:

    <script type="text/javascript">
        jQuery(document).ready(function() {
            $('#auto_complete').typeahead({source: autocomplete_items});
        });
    </script>
    

    Additionally there is an Autocomplete gem for Rails 3 which will work directly with your models rather than passing off the object to your Javascript. There is even a Formtastic example in the documentation.

    Edit: It looks like I didn’t read your whole question! Unfortunately HTML5 Data Attributes are currently unsupported with Formtastic. There is however a separate branch that does include support for these attributes.

    Other than that there’s always just sticking with Good ol’ HTML/ERB for dynamic features like this…

    <input type="text" class="span3" style="margin: 0 auto;" data-provide="typeahead" data-items="8" data-source='<%= @autocomplete_items.to_json %>'>
    

    EDIT 2: I’ve just noticed two things. First being the way I was passing the JSON object to a Javascript variable (see the example). Secondly, the above example using HTML5 data attributes will not work with Twitter’s Typeahead plugin, but it will work with the jQuery UI Autocomplete plugin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to integrate full-text search into a .NET application with [Fluent] NHibernate-based data
I would like to integrate a custom font into a synth style. I found
I'd like to integrate user comments for a Facebook or Group on my website.
I need to integrate the functionality of creating dynamic pages (like google sites) to
I am trying to integrate NHibernate.Search into a multi-lingual website. Now, this website contains
I am trying to integrate OpenFeint 2.12.5 into my app. I already read this
I have to integrate a Java applet into a simple asp.net 2.0 control. This
I want to integrate mutiple LDAP (AD, OpenDS, OpenLDAP etc) user data into one
I'm trying to integrate Jawr into my Spring application: <bean abstract=true id=jawrBase class=net.jawr.web.servlet.JawrSpringController> <property
I would like to integrate the iPhone call functionality with my sample application. I

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.