Test: search company with jQuery

This commit is contained in:
Regis Houssin 2010-10-08 15:28:18 +00:00
parent 1af2a5025f
commit 340a3f4bcc
3 changed files with 25 additions and 15 deletions

View File

@ -553,11 +553,6 @@ class Form
$socid = $obj->rowid?$obj->rowid:'';
}
// We call a page after a small delay when a new input has been selected
//$javaScript = "window.location=\'...\'";
//$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"';
$htmloption='';
print "\n".'<!-- Input text for third party with Ajax.Autocompleter (select_societes) -->'."\n";
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
print '<td class="nobordernopadding">';
@ -565,12 +560,11 @@ class Form
print '<div class="ui-widget">';
if ($socid == 0)
{
//$langs->load("companies");
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="" '.$htmloption.' />';
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="" />';
}
else
{
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$obj->nom.'" '.$htmloption.' />';
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$obj->nom.'" />';
}
print '</div>';
//print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socid',DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), '');

View File

@ -91,11 +91,27 @@ function ajax_autocompleter($selected='',$htmlname,$value,$url,$indicator='worki
$script.= '<script type="text/javascript">';
$script.= 'jQuery(document).ready(function() {
jQuery("#'.$htmlname.'").autocomplete({
source: "'.$url.'",
source: function( request, response ) {
jQuery.ajax({
url: "'.$url.'",
dataType: "jsonp",
data: {
socid: request.term
},
success: function( data ) {
response( $.map( data.result, function( item ) {
return {
label: item.socname,
value: item.socid
}
}));
}
});
},
minLength: 2,
select: function( event, ui ) {
jQuery("#'.$htmlname.'").val(ui.item.socname);
jQuery("#'.$value.'").val(ui.item.socid);
jQuery("#'.$htmlname.'").val(ui.item.label);
jQuery("#'.$value.'").val(ui.item.value);
}
});
});';

View File

@ -55,13 +55,13 @@ dol_syslog(join(',',$_GET));
// Generation liste des societes
if (! empty($_POST['newcompany']) || ! empty($_GET['term']) || ! empty($_POST['id_fourn']))
if (! empty($_POST['newcompany']) || ! empty($_GET['socid']) || ! empty($_POST['id_fourn']))
{
$return_arr = array();
// Define filter on text typed
$socid = $_POST['newcompany']?$_POST['newcompany']:'';
if (! $socid) $socid = $_GET['term']?$_GET['term']:'';
if (! $socid) $socid = $_GET['socid']?$_GET['socid']:'';
if (! $socid) $socid = $_POST['id_fourn']?$_POST['id_fourn']:'';
$sql = "SELECT rowid, nom";
@ -100,8 +100,8 @@ if (! empty($_POST['newcompany']) || ! empty($_GET['term']) || ! empty($_POST['i
}
print '</ul>';
*/
echo json_encode($return_arr);
$result = array('result' => $return_arr);
echo json_encode($result);
}
}
else