Hi , I can not do the twitter bootstrap component typeahead work with cake. i use https://github.com/rudylee/cbunny , but dont work form me.
-- In my view
JS
<script type="text/javascript">
$(document).ready(function(){
$('#itemdesc').typeahead({
source: function (query, process) {
return $.ajax({
url:'<?php echo Router::url(array('controller'=>'Invoices','action'=>'localizaprodutos'));?>',
type: 'get',
data: {q: query},
dataType: 'json',
success: function (json) {
return process(json);
}
});
}
});
});
</script>
HTML
<input type="text" name="itemdesc[]" class="input-large" id="itemdesc" data-provide="typeahead"/>
and controller
public function localizaprodutos(){
$this->autoRender = false;
$this->RequestHandler->respondAs('json');
// get the search term from URL
$term = $this->request->query['q'];
$users = $this->Invoice->Invoicedetail->Inventoryitem->find('all',array(
'conditions' => array(
'Inventoryitem.desc LIKE' => '%'.$term.'%'
)
));
// Format the result for select2
$result = array();
foreach($produtos as $key => $produto) {
array_push($result, $produto['Inventoryitem']['desc']);
}
$produtos = $result;
echo json_encode($produtos);
}
Thanks
Renato
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment