[bootstrap] typeahead

Costas

Administrator
Staff member
plain bootstrap v2.x, combo autocomplete

With Twitter bootstrap v3 the typeahead plugin had been dropped. @mdo says: "in favor of folks using Twitter's typeahead. Twitter's typeahead has more features than the old bootstrap-typeahead.js and less bugs." more http://twitter.github.io/typeahead.js/

Snap320.png


JavaScript:
<input type="text" class="form-control" id="test" placeholder="fullname">

JavaScript:
var search = $('input#test');

$(search).typeahead({
    source: [
        'Dave Mustaine',
        'Tom Morello',
        'Jim Root',
        'Kirk Hammett',
        'Joe Perry',
        'Jimi Hendrix',
        'Eric Clapton',
        'Billy Duffy',
        'Johnny Hickman',
        'Eddie Van Halen',
        'Dimebag Darrell',
        'Noel Gallagher'
    ],
    items: 5
});

 

 
fuck it, dont waste your time, use :
https://github.com/bassjobsen/Bootstrap-3-Typeahead

truly working.

JavaScript:
//https://github.com/bassjobsen/Bootstrap-3-Typeahead/issues/99#issuecomment-76320058
$('#search_box').typeahead({
    source: function (query, process) {
        return $.get("node_search.php?txt=" + query, function (data) {
        	console.log(data);
            return process(data);
        },'json');
    }
});

JavaScript:
//node_search.php
<?php
require_once ('config.php');

$db = connect_mysql();

$rows = getSet($db,"select node_id as id, node_title as name from nodes where node_body like CONCAT('%', ?, '%') or node_title like CONCAT('%', ?, '%')",array($_GET['txt'],$_GET['txt']));

$r = array();
foreach($rows as $row) {
	$r[] = array("id" => $row["id"], "name" => $row["name"]);
}

echo json_encode($r);
 
Top