Welcome Guest, Not a member yet? Register   Sign In
jquery autocomplete
#1

[eluser]Gorazd Reichman[/eluser]
Hello,

This is my first post on this forum. I have been using CI for a while now.
It is great but I miss some ajax functionality. As I have read on this forum we can expect some sort ajax/JQuery support in the near future but I needed a solution right now, so I wrote simple JQuery autocomplete libraray for use in CI.

Library:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class JQuery {

    var $el_Num;
    var $AjaxDelay ;
    var $AjaxBaseUrl ;
    var $AjaxMinChars ;
    var $scripts ;

    function JQuery()
    {
        $this->CI =& get_instance();
        $this->el_Num = array() ;
        $this->AjaxDelay = 500 ;
        $this->AjaxMinChars = 3 ;
        $this->AjaxBaseUrl = "" ;
        $this->scripts = array() ;
        $this->CI->load->helper('form') ;
    }
    
    function setAjaxDelay($delay)
    {
        $this->AjaxDelay = $delay ;
    }
    
    function setAjaxMinChars($chars)
    {
        $this->AjaxMinChars = $chars ;
    }
    
    function setAjaxBaseUrl($url)
    {
        $this->AjaxBaseUrl = $url ;
    }
    
    function loadJScript($src)
    {
        $this->scripts[] = $src ;
    }
    
    function JScript()
    {
        $output = "" ;
        foreach ($this->scripts as $script)
        {
            $output .= '[removed][removed]' ;
        }
        $output .= '[removed]' ;
        $output .= 'var autocomplete_baseurl = "'.$this->AjaxBaseUrl.'" ;' ;
        $output .= 'var autocomplete_delay = '.$this->AjaxDelay.' ;' ;
        $output .= 'var autocomplete_minchars = '.$this->AjaxMinChars.' ;' ;
        $output .= '[removed]' ;
        return $output ;
    }
    
    function form_autocomplete($ajaxFunction, $hidden = FALSE, $data = '', $value = '', $extra = '')
    {
        if (!array_key_exists($ajaxFunction,$this->el_Num)) $this->el_Num[$ajaxFunction] = 0 ;
        $this->el_Num[$ajaxFunction]++ ;
        $output = form_input($data,$value,'class="autocomplete" id="'.$ajaxFunction.'_'.$this->el_Num[$ajaxFunction].'" '.$extra) ;
        if ($hidden)
        {
            $output .= form_hidden("hidden".$ajaxFunction.'_'.$this->el_Num[$ajaxFunction]) ;
        }
        return $output ;
    }
        
}
// end of class


Messages In This Thread
jquery autocomplete - by El Forum - 01-24-2009, 02:17 AM
jquery autocomplete - by El Forum - 01-24-2009, 02:20 AM
jquery autocomplete - by El Forum - 01-24-2009, 02:24 AM
jquery autocomplete - by El Forum - 01-24-2009, 05:08 AM
jquery autocomplete - by El Forum - 01-24-2009, 06:16 AM
jquery autocomplete - by El Forum - 01-24-2009, 09:37 AM
jquery autocomplete - by El Forum - 01-24-2009, 09:49 AM
jquery autocomplete - by El Forum - 01-24-2009, 07:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB