Jump to content

Admin Area Intelligent Search While Typing


sentq

Recommended Posts

To activate the intelligent search to query results while typing instead of pressing the "Enter" key each time I have created simple ActionHook function that will integrate the code for both built-in template (v4 and Blend), the integration tested and is valid for WHMCS v6+ and v7+

1) Create new PHP file inside /includes/hooks/ directory, you may use "IntelliSearchWhileTyping.php" as the file name or whatever you prefer.

2) Copy the following code inside it.

3) Done.

<?php
/**
 * Get Results From Intelligent Search While Typing
 *
 * Compatible with WHMCS v6+ and v7+
 * Works with v4 and Blend templates
 *
 * @author     SENTQ <development@sentq.com>
 * 
 */

if (!defined("WHMCS")){
    die("This file cannot be accessed directly");
}

add_hook("AdminAreaHeadOutput", 1, function($vars){
    
    # Template Blend
    if ($vars['template'] === "blend"){
        
        return <<<EOF
<script type="text/javascript">
/* Intelligent Search On Typing */
$(document).ready(function(){
   $(document).on("input", "#intellisearchval", function(){
       $("#intellisearchval").css("background-image","url('images/loading.gif')");
       $.post("search.php", $("#frmintellisearch").serialize(),
       function(data){
           $("#searchresultsscroller").html(data);
           $("#searchresults").slideDown("slow",function(){
                   $("#intellisearchval").css("background-image","url('images/icons/search.png')");
               });
       });
   });
});
</script>
EOF;
    
    }
    # Template v4
    elseif ($vars['template'] === "v4"){
        
        return <<<EOF
<script type="text/javascript">
/* Intelligent Search On Typing */
$(document).ready(function(){
    $(document).on("input", "#intellisearchval", function() {
       $.post("search.php", $("#frmintellisearch").serialize(),
       function(data){
           if (data) {
               $("#searchresults").html(data);
               $("#btnIntelliSearch").hide();
               $("#btnIntelliSearchCancel").removeClass('hidden').show();
               $("#searchresults").hide().removeClass('hidden').slideDown();
           }
       });
   });
});
</script>
EOF;
        
    }
        
});
 

IntelliSearchWhileTyping.php

Edited by sentq
improvements and v7.1+ integration
Link to comment
Share on other sites

Thanks for that. Shame it does not work for the V4 templates.

Use the following code instead to apply the same functionality to v4 template:

/* Intelligent Search On Typing */
$(document).ready(function(){
    $("#intellisearchval").on("keyup", function() {
       $.post("search.php", $("#frmintellisearch").serialize(),
       function(data){
           if (data) {
               $("#searchresults").html(data);
               $("#btnIntelliSearch").hide();
               $("#btnIntelliSearchCancel").removeClass('hidden').show();
               $("#searchresults").hide().removeClass('hidden').slideDown();
           }
       });
   });
});

Link to comment
Share on other sites

  • 5 weeks later...
  • 2 months later...
  • 8 months later...
On 10/2/2015 at 10:36 AM, sentq said:

To activate the intelligent search to query results while typing instead of pressing the "Enter" key each time I have created simple ActionHook function that will integrate the code for both built-in template (v4 and Blend), the integration tested and is valid for WHMCS v6+ and v7+

1) Create new PHP file inside /includes/hooks/ directory, you may use "IntelliSearchWhileTyping.php" as the file name or whatever you prefer.

2) Copy the following code inside it.

3) Done.


<?php
/**
 * Get Results From Intelligent Search While Typing
 *
 * Compatible with WHMCS v6+ and v7+
 * Works with v4 and Blend templates
 *
 * @author     SENTQ <development@sentq.com>
 * 
 */

if (!defined("WHMCS")){
    die("This file cannot be accessed directly");
}

add_hook("AdminAreaHeadOutput", 1, function($vars){
    
    # Template Blend
    if ($vars['template'] === "blend"){
        
        return <<<EOF
<script type="text/javascript">
/* Intelligent Search On Typing */
$(document).ready(function(){
   $(document).on("input", "#intellisearchval", function(){
       $("#intellisearchval").css("background-image","url('images/loading.gif')");
       $.post("search.php", $("#frmintellisearch").serialize(),
       function(data){
           $("#searchresultsscroller").html(data);
           $("#searchresults").slideDown("slow",function(){
                   $("#intellisearchval").css("background-image","url('images/icons/search.png')");
               });
       });
   });
});
</script>
EOF;
    
    }
    # Template v4
    elseif ($vars['template'] === "v4"){
        
        return <<<EOF
<script type="text/javascript">
/* Intelligent Search On Typing */
$(document).ready(function(){
    $(document).on("input", "#intellisearchval", function() {
       $.post("search.php", $("#frmintellisearch").serialize(),
       function(data){
           if (data) {
               $("#searchresults").html(data);
               $("#btnIntelliSearch").hide();
               $("#btnIntelliSearchCancel").removeClass('hidden').show();
               $("#searchresults").hide().removeClass('hidden').slideDown();
           }
       });
   });
});
</script>
EOF;
        
    }
        
});
 

IntelliSearchWhileTyping.php

It appears to have crashed in the latest stable version of WHMCS (v7.6.1)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated