Autosuggest jQuery KumbiaPHP
De KumbiaPHP Framework Wiki
| Este Artículo esta siendo revisado por los Kumbieros. Puedes tomar la información que aqui se encuentra pero no nos hacemos responsable |
Contenido |
[editar] Librerías
Lo primero que se tiene que hacer es descargar el plugin de jquery autosuggest.
[editar] En el Partial
Creamos el Partial donde se va llamar la función autoSuggest, Este Partial va recibir 3 parámetros para así hacerlo mas reutilizable, el id del campo, el controlador y la acción.
<?php stylesheet_link_tag('autoSuggest'); echo javascript_include_tag('jquery.autoSuggest'); ?> <script type="text/javascript"> $(document).ready(function () { $("#<?php echo $id ?>").autoSuggest("<?php echo PUBLIC_PATH."$controlador/$accion"?>", { minChars: 2, matchCase: true, selectedItemProp: "name", searchObjProps: "name" }); }); </script>
[editar] En el Formulario
En en la vista donde va ir el campo de texto que va usar el plugin agregamos el partial y le asiganmos sus 3 parámetros. el ID del campo, La accion, El controlador.
<?php echo form_tag('registro/create/') //¬¬_ ?> <table> <tr> <td>Accesorios</td> <td><?php echo text_field_tag('tipoactivo.accesorios') ?></td> </tr> <tr> <td> </td> <td><?php echo submit_tag('Agregar') ?></td> </tr> </table> <?php echo end_form_tag() ?> <?php View::partial('jquery/autoSuggest', false , array('id'=>'tipoactivo_accesorios','accion'=>'listaracc', 'controlador'=>'registro'))?>
[editar] En el Controlador
public function listaracc(){ $this->set_response('view'); $input = $this->get("q"); $accesorio = new Accesorios(); $this->array = $accesorio->find("accesorio like '%$input%'"); }
[editar] En la Vista
<?php $data = array(); foreach ($array as $cat) { $json = array(); $json['value'] = $cat->id; $json['name'] = $cat->accesorio; $data[] = $json; } header("Content-type: application/json"); echo json_encode($data); ?>
Christopher

