Search Form Field

How to use the Search Field addField() and all it's parameters

The Search field parameters are as follow:

 

addField([
   'type'=>'search', //required
   'attributes'=>'required autofocus', //optional
   'label'=>'FIND CLIENT', //required
   'name'=>'CLID', //optional
   'ID'=>'MAINCLID', //optional
   'value'=>'',  //optional (required on edit to preserve value)
   'text'=>'',  //optional, the text to be shown instead of placeholder when a value exists (required on edit to preserve value)
   'placeholder'=>'SEARCH CLIENT NAME, EMAIL or COMPANY', //optional
   'data'=>[ //required
      'searchCols'=>'CLID,NAME,COMPANY,EMAIL,LNAME', //required (these are for searchCols like %search query%)
      'table'=>'CLIENTS', //required
      'colID'=>'CLID', //required
      'order' => 'CLIENTS.COMPANY ASC', //optional
      'where' => 'CLIENTS.ACTIVE = 1', //optional
      'limit' => 20,  //optional 20 by default
      'format'=>'<span onclick="getClientCategory(CATID)"><b>COMPANY</b>, NAME, LNAME,<br/>&lt;EMAIL&gt;</span>', //optional &lt;EMAIL&gt; shows <EMAIL>
      //'callback' => 'gotoClient();',  //optional
      'result'=>'CATID,COMPANY,NAME,LNAME,EMAIL'  //required (this is the Select part of the query, they will match the values in fomrat)
   ]
]);

 

JS Script Example used from the onclick function

<script>
function getClientCategory(CATID){
$.ajax({
 // Set Category from client
 $('#CATID').value(CATID);
}
</script>

 

In the case where a JOIN is required, do so in the TABLE value.

 

addField([
   'type'=>'search', //required
   'label'=>'FIND PRODUCT', //required
   'id'=>'inventory_item', //optional
   'placeholder'=>'Search by product name', //optional
   'data'=>[ //required
   'url'=>'ajax/getInventoryProduct.php', //optional (getSearch.php bu default)
     'searchCols'=> 'B.title_'.$kas['main_lang'].',P.title_'.$kas['main_lang'], //required (these are for searchCols like %search query%)
     'table'=>'PRODUCTS P LEFT JOIN PRODUCTS_BRANDS B on P.PBID = B.PBID', //required
     'colID'=>'PRID', //required
     'order' => 'B.title_'.$kas['main_lang'].' ASC ,P.title_'.$kas['main_lang'].' ASC', //optional
     'where' => 'P.visible = 1', //optional
     'limit' => 20,  //optional 20 by default
     'format'=>'<b>brand product</b>, (stock available)', //optional &lt;EMAIL&gt; shows <EMAIL>
     'callback' => 'getProduct();',  //optional
     'result'=>'P.PRID as PRODID, B.title_'.$kas['main_lang'].' as brand,P.title_'.$kas['main_lang'].' as product,global_inventory as stock'  //required (this is the Select part of the query, they will match the values in fomrat)
   ]

]);

 

JS Script Example used from the callback function

<script>
function getProduct(){
   $.ajax({
 url:'ajax/invoiceActions.php',
 type:'POST',
 data:{
 action:'load_product',
 PRID:$('#hiddeninventory_item').val()
        },success:function(response){
         let product = JSON.parse(response);
         CKEDITOR.instances['description'].setData(product.PRODUCT);
     }
  });
}
</script>

 

FORMAT lets you give format to the result, it is a CSV, where each value is assigned in the same order to the ones in RESULT, the number of comma separated values must be equal to the one in result

For example:

FORMAT = '<strong>COLNAME</strong>,<br/>COLNAME,<i>COLNAME</i>',

returns

FIRST RESULT,
SECOND RESULT, $THIRD RESULT

as for the CALLBACK, it will execute any javascript coded assigned here. also use equal instead of '='