Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorsuthern
     

    Howdy Jerome,

    I noticed that the header of this file says "These macros are deprecated and will be removed on Akelos 0.9".

    What is replacing them? I'm curious, as I'd love to do an autocomplete that does not depend on features which are being removed. Thanks for any tips!

    • CommentAuthorsuthern
     

    Well, here is what I've done. It's a bit hick-hacky, so beware. Feel free to comment. Currently I'm looking for a way to do it without adding the ROUTE line into my routes.php file.

    I decided to look around for a good dropdown menu, and found a nice one over at webeaters

    1. I downloaded the newsest version.
    2. copied autocomplete/images/autocomplete/*.gif --> /public/images/autocomplete/
    3. copied autocomplete/js/*.js --> /public/javascripts/ (overwriting the old prototype.js with the new one)
    4. copied autocomplete/css/autocomplete.css --> /public/stylesheets/autocomplete.css

    With the files in place, I began some exploring, hair pulling, coding, and sweating. Finally it worked! Error reporting is VERY minimal in this setup.

    Without further ado, here are the relevant parts of my files

    /routes.php

    $Map->connect('/spot/auto_complete_for_spot_find/:input', array('controller' => 'spot', 'action' => 'auto_complete_for_spot_find', 'input' => OPTIONAL ));

    /spot_controller.php

    function auto_complete_for_spot_find() { $input = ltrim($this->params['input'],"="); $parts = $this->Part->find_parts($input); if(is_null($parts) || empty($parts)) { $this->spots = array(array('id' => 1, 'value' => 'No Parts Found', 'info' => '--'.$input.'--')); } else { foreach($parts as $k => $part) { $this->spots[] = array('id' => $part['id'], 'info' => mysql_real_escape_string($part['description']), 'value' => mysql_real_escape_string($part['our_code']) ); } } $this->renderPartial("ajaxPartial.tpl"); }

    /layouts/spot.tpl

    <?php echo $asset_tag_helper->javascript_include_tag('autocomplete.js') ?> <?php echo $asset_tag_helper->stylesheet_link_tag('autocomplete') ?>

    /models/part.php (double backtics inserted for readability only)

    function find_parts($input,$limit=6)
    {
        // search via our_code
        $parts = $this->_db->execute(array('
            SELECT p.* FROM ``parts`` AS p WHERE p.our_code LIKE ? LIMIT ?
            ','%'.$input.'%',$limit));
        if(!$parts->EOF) return $this->row2array($parts);
        //search via our part description
        $parts = $this->_db->execute(array('
            SELECT p.* FROM ``parts`` AS p WHERE p.description LIKE ? LIMIT ?
            ','%'.$input.'%',$limit));
        if(!$parts->EOF) return $this->row2array($parts);
        //search via list price
        $parts = $this->_db->execute(array('
            SELECT p.* FROM ``parts`` AS p JOIN ``list_prices`` AS lp ON p.manufacturer_code = lp.code AND p.manufacturer_id = lp.manufacturer_id
            WHERE lp.description LIKE ? LIMIT ?
            ','%'.$input.'%',$limit));
        if(!$parts->EOF) return $this->row2array($parts);
        // search via barcodes...(todo)
        return null;
    }
    

    /views/spot/find_spot.tpl

    echo $all_helper->text_field_with_auto_complete('spot','loc_code','auto_complete_for_spot_find');

    /helpers/all_helper.php (is a file I have for application-wide helpers)

    function text_field_with_auto_complete($model,$field,$action,$html_options=array())
    {
        $on_focus_option = array('OnFocus' => "javascript: 
            var options = {
                script:'".$this->_controller->url_helper->url_for(array('action' => $action))."',
                varname:'',
                json:true,
                shownoresults:true,
                limit:6,
                maxresults:16,
                callback: function (obj) { ".'$'."('json_info'); }
                };
                var json=new AutoComplete('".$model."_".$field."',options);return true;"
            );
        $html_options = array_merge($html_options,$on_focus_option);
        $st = "<span>".$this->_controller->form_helper->text_field($model,$field,$html_options);
        $st .= "</span><span id='json_info'></span>";
    
        return $st;
    }
    

    /views/spot/_ajaxPartial.tpl

    {?spots} { results: [ {loop spots} { id: "{spot-id}", value: "{spot-value}", info: "{spot-info}" }, {end} {end} ] } My main gripe is that when it dosen't work, there are NO errors thrown anywhere.

    The 2nd problem is there's no easy place to modify the dropdown (somewhere deep inside autocomplete.js) to include other fields, etc.

    The 3rd issue is having to make a new route for every type of autocomplete-searching that I want to do.

    Just thought I'd post this for someone looking for more information on autocompletion.