Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Autocomplete in the Calendar UI
#8
Now I've done that as well. The jQuery is now expanded. The autocomplete call for sales orders is now like:

PHP Code:
        jQuery"#so_autocomplete" ).autocomplete({
        
// Beware: Autocomplete sets a search term as GET parameter to the URL
        // The php file has to take this into account and use the search term
        // in its mySQL query
          
source"http://crmdevelop.cbx-nederland.nl/index.php?module=Calendar4You&action=Calendar4YouAjax&searchmodule=SalesOrders&file=JSON",
        
// On open we have to set a high z-index to the UL, else it will
        // fall behind the 'addEvent' UI box
          
open: function(){
            
jQuery(this).autocomplete('widget').css('z-index'999999);
            return 
false;
          },
          
// Here we add the result on selection to a hidden input field
          // That the calendar module uses to connect a crmentity
          
select: function( eventui) {
              
// Add crmentity id to hidden input
              
jQuery('input[name=so_rel]').attr('value',ui.item.value);
              
// Overwrite the input field with the salesorder name in stead of the crmentity
              
jQuery('#so_autocomplete').val(ui.item.label);
              return 
false;
          },
          
// Also update the input field with the label during focus
          
focus: function( eventui ) {
              
// Overwrite the input field with the salesorder name in stead of the crmentity
              
jQuery('#so_autocomplete').val(ui.item.label);
              return 
false;
          },
          
minLength2
        
// Make sure browser 'autocomplete' is turned on for this field
        
}).attr("autocomplete","off")
        
// Add '_renderItem' to use HTML in the results, so we can use
        // things like address fields and better readable markup
        
.autocomplete"instance" )._renderItem = function( ulitem ) {
          return 
jQuery"<li>" )
            .
append"<a>" "<b>" item.label "</b>" "<br>" item.subject "<br>" item.accountname "</a>" )
            .
appendToul );
        };
        
// During typing, dynamically change the autocomplete source to check for accountID
        
jQuery("#so_autocomplete").keyup(function(){
            
jQuery"#so_autocomplete" ).autocomplete("option","source","http://crmdevelop.cbx-nederland.nl/index.php?module=Calendar4You&action=Calendar4YouAjax&searchmodule=SalesOrders&accountid="+jQuery('input[name=parent_id]').val()+"&file=JSON");
        }); 

And a few line changed in the JSON.php file:

PHP Code:
        // Get the salesorders that match part of the search term
        // Check to see if there was an account ID passed in the URL
        
if (isset($_REQUEST['accountid']) && $_REQUEST['accountid'] != "") {
            
// If account ID was set, use it in the query
            
$soAccountID $_REQUEST['accountid'];
            
$soresults $adb->query("SELECT subject, salesorderid, salesorder_no, accountid FROM vtiger_salesorder WHERE salesorder_no LIKE '%$term%' AND accountid = $soAccountID");
        } else {
            
// If no account was selected
            
$soresults $adb->query("SELECT subject, salesorderid, salesorder_no, accountid FROM vtiger_salesorder WHERE salesorder_no LIKE '%$term%'");
        } 

Replaced the old query. Now, when you've selected an account, the sales order autocomplete will filter to show only sales orders from this account.
Reply


Messages In This Thread
RE: Autocomplete in the Calendar UI - Guido1982 - 11-17-2015, 04:09 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)