Test: search company with jQuery
This commit is contained in:
parent
1af2a5025f
commit
340a3f4bcc
@ -553,11 +553,6 @@ class Form
|
|||||||
$socid = $obj->rowid?$obj->rowid:'';
|
$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 "\n".'<!-- Input text for third party with Ajax.Autocompleter (select_societes) -->'."\n";
|
||||||
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
|
print '<table class="nobordernopadding"><tr class="nocellnopadd">';
|
||||||
print '<td class="nobordernopadding">';
|
print '<td class="nobordernopadding">';
|
||||||
@ -565,12 +560,11 @@ class Form
|
|||||||
print '<div class="ui-widget">';
|
print '<div class="ui-widget">';
|
||||||
if ($socid == 0)
|
if ($socid == 0)
|
||||||
{
|
{
|
||||||
//$langs->load("companies");
|
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="" />';
|
||||||
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="" '.$htmloption.' />';
|
|
||||||
}
|
}
|
||||||
else
|
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 '</div>';
|
||||||
//print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socid',DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), '');
|
//print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socid',DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), '');
|
||||||
|
|||||||
@ -91,11 +91,27 @@ function ajax_autocompleter($selected='',$htmlname,$value,$url,$indicator='worki
|
|||||||
$script.= '<script type="text/javascript">';
|
$script.= '<script type="text/javascript">';
|
||||||
$script.= 'jQuery(document).ready(function() {
|
$script.= 'jQuery(document).ready(function() {
|
||||||
jQuery("#'.$htmlname.'").autocomplete({
|
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,
|
minLength: 2,
|
||||||
select: function( event, ui ) {
|
select: function( event, ui ) {
|
||||||
jQuery("#'.$htmlname.'").val(ui.item.socname);
|
jQuery("#'.$htmlname.'").val(ui.item.label);
|
||||||
jQuery("#'.$value.'").val(ui.item.socid);
|
jQuery("#'.$value.'").val(ui.item.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});';
|
});';
|
||||||
|
|||||||
@ -55,13 +55,13 @@ dol_syslog(join(',',$_GET));
|
|||||||
|
|
||||||
|
|
||||||
// Generation liste des societes
|
// 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();
|
$return_arr = array();
|
||||||
|
|
||||||
// Define filter on text typed
|
// Define filter on text typed
|
||||||
$socid = $_POST['newcompany']?$_POST['newcompany']:'';
|
$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']:'';
|
if (! $socid) $socid = $_POST['id_fourn']?$_POST['id_fourn']:'';
|
||||||
|
|
||||||
$sql = "SELECT rowid, nom";
|
$sql = "SELECT rowid, nom";
|
||||||
@ -100,8 +100,8 @@ if (! empty($_POST['newcompany']) || ! empty($_GET['term']) || ! empty($_POST['i
|
|||||||
}
|
}
|
||||||
print '</ul>';
|
print '</ul>';
|
||||||
*/
|
*/
|
||||||
|
$result = array('result' => $return_arr);
|
||||||
echo json_encode($return_arr);
|
echo json_encode($result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user