Début ajout de l'autocomplétion ajax sur la liste déroulante des pays
This commit is contained in:
parent
673c6a2fda
commit
602473dced
@ -47,22 +47,24 @@ if(isset($_GET['keyref']) && !empty($_GET['keyref']) || isset($_GET['keylabel'])
|
|||||||
|
|
||||||
|
|
||||||
// Generation liste des pays
|
// Generation liste des pays
|
||||||
if(isset($_POST['search']) && !empty($_POST['search']))
|
if(isset($_POST['pays']) && !empty($_POST['pays']))
|
||||||
{
|
{
|
||||||
print 'hello world';
|
|
||||||
$sql = "SELECT rowid, code, libelle, active";
|
$sql = "SELECT rowid, code, libelle, active";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
|
$sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
|
||||||
$sql.= " WHERE active = 1 AND libelle LIKE '%" . $_POST['search'] . "%'";
|
$sql.= " WHERE active = 1 AND libelle LIKE '%" . $_POST['pays'] . "%'";
|
||||||
$sql.= " ORDER BY code ASC;";
|
$sql.= " ORDER BY libelle ASC;";
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
|
||||||
|
|
||||||
|
$resql=$db->query($sql);
|
||||||
|
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
print '<ul>';
|
print '<ul>';
|
||||||
while($data = mysql_fetch_assoc($resql))
|
while($data = mysql_fetch_assoc($resql))
|
||||||
{
|
{
|
||||||
print '<li>'.stripslashes($data['libelle']).'</li>';
|
print '<li>';
|
||||||
|
print stripslashes($data['libelle']);
|
||||||
|
print '<span class="informal" style="display:none">'.$data['rowid'].'-idcache</span>';
|
||||||
|
print '</li>';
|
||||||
}
|
}
|
||||||
print '</ul>';
|
print '</ul>';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -323,11 +323,12 @@ class Form
|
|||||||
if ($conf->use_ajax && $conf->global->CODE_DE_TEST == 1)
|
if ($conf->use_ajax && $conf->global->CODE_DE_TEST == 1)
|
||||||
{
|
{
|
||||||
print '<div>';
|
print '<div>';
|
||||||
print '<input type="text" id="search" name="search" />';
|
print '<input type="text" size="45" id="pays" name="pays" />';
|
||||||
|
print '<input type="hidden" name="pays_id" id="pays_id" value="" '.$htmloption.' />';
|
||||||
print '</div>';
|
print '</div>';
|
||||||
print '<div id="hint"></div>';
|
print '<div id="hint" class="autocomplete"></div>';
|
||||||
print '<script type="text/javascript">';
|
print '<script type="text/javascript">';
|
||||||
print 'new Ajax.Autocompleter(\'search\',\'hint\',\''.DOL_URL_ROOT.'/ajaxresponse.php\');';
|
print 'new Ajax.Autocompleter(\'pays\',\'hint\',\''.DOL_URL_ROOT.'/ajaxresponse.php\',{method: \'post\',paramName: \'pays\',afterUpdateElement: ac_return});';
|
||||||
print '</script>';
|
print '</script>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -398,61 +398,61 @@ document.onmousemove=positiontip;
|
|||||||
|
|
||||||
|
|
||||||
/*=================================================================
|
/*=================================================================
|
||||||
Function: formatDate (javascript object Date(), format)
|
Function: formatDate (javascript object Date(), format)
|
||||||
Purpose: Returns a date in the output format specified.
|
Purpose: Returns a date in the output format specified.
|
||||||
The format string can use the following tags:
|
The format string can use the following tags:
|
||||||
Field | Tags
|
Field | Tags
|
||||||
-------------+-------------------------------
|
-------------+-------------------------------
|
||||||
Year | yyyy (4 digits), yy (2 digits)
|
Year | yyyy (4 digits), yy (2 digits)
|
||||||
Month | MM (2 digits)
|
Month | MM (2 digits)
|
||||||
Day of Month | dd (2 digits)
|
Day of Month | dd (2 digits)
|
||||||
Hour (1-12) | hh (2 digits)
|
Hour (1-12) | hh (2 digits)
|
||||||
Hour (0-23) | HH (2 digits)
|
Hour (0-23) | HH (2 digits)
|
||||||
Minute | mm (2 digits)
|
Minute | mm (2 digits)
|
||||||
Second | ss (2 digits)
|
Second | ss (2 digits)
|
||||||
Author: Laurent Destailleur
|
Author: Laurent Destailleur
|
||||||
Licence: GPL
|
Licence: GPL
|
||||||
==================================================================*/
|
==================================================================*/
|
||||||
function formatDate(date,format)
|
function formatDate(date,format)
|
||||||
{
|
{
|
||||||
//alert('formatDate date='+date+' format='+format);
|
//alert('formatDate date='+date+' format='+format);
|
||||||
|
|
||||||
// Force parametres en chaine
|
// Force parametres en chaine
|
||||||
format=format+"";
|
format=format+"";
|
||||||
|
|
||||||
var result="";
|
var result="";
|
||||||
|
|
||||||
var year=date.getYear()+""; if (year.length < 4) { year=""+(year-0+1900); }
|
var year=date.getYear()+""; if (year.length < 4) { year=""+(year-0+1900); }
|
||||||
var month=date.getMonth()+1;
|
var month=date.getMonth()+1;
|
||||||
var day=date.getDate();
|
var day=date.getDate();
|
||||||
var hour=date.getHours();
|
var hour=date.getHours();
|
||||||
var min=date.getMinutes();
|
var min=date.getMinutes();
|
||||||
var seconde=date.getSeconds();
|
var seconde=date.getSeconds();
|
||||||
|
|
||||||
var i=0;
|
var i=0;
|
||||||
while (i < format.length)
|
while (i < format.length)
|
||||||
{
|
{
|
||||||
c=format.charAt(i); // Recupere char du format
|
c=format.charAt(i); // Recupere char du format
|
||||||
substr="";
|
substr="";
|
||||||
j=i;
|
j=i;
|
||||||
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques
|
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques
|
||||||
{
|
{
|
||||||
substr += format.charAt(j++);
|
substr += format.charAt(j++);
|
||||||
}
|
}
|
||||||
|
|
||||||
//alert('substr='+substr);
|
//alert('substr='+substr);
|
||||||
if (substr == 'yyyy') { result=result+year; }
|
if (substr == 'yyyy') { result=result+year; }
|
||||||
else if (substr == 'yy') { result=result+year.substring(2,4); }
|
else if (substr == 'yy') { result=result+year.substring(2,4); }
|
||||||
else if (substr == 'MM') { result=result+(month<1||month>9?"":"0")+month; }
|
else if (substr == 'MM') { result=result+(month<1||month>9?"":"0")+month; }
|
||||||
else if (substr == 'd') { result=result+day; }
|
else if (substr == 'd') { result=result+day; }
|
||||||
else if (substr == 'dd') { result=result+(day<1||day>9?"":"0")+day; }
|
else if (substr == 'dd') { result=result+(day<1||day>9?"":"0")+day; }
|
||||||
else if (substr == 'hh') { if (hour > 12) hour-=12; result=result+(hour<1||hour>9?"":"0")+hour; }
|
else if (substr == 'hh') { if (hour > 12) hour-=12; result=result+(hour<1||hour>9?"":"0")+hour; }
|
||||||
else if (substr == 'HH') { result=result+(hour<1||hour>9?"":"0")+hour; }
|
else if (substr == 'HH') { result=result+(hour<1||hour>9?"":"0")+hour; }
|
||||||
else if (substr == 'mm') { result=result+(minute<1||minute>9?"":"0")+minute; }
|
else if (substr == 'mm') { result=result+(minute<1||minute>9?"":"0")+minute; }
|
||||||
else if (substr == 'ss') { result=result+(seconde<1||seconde>9?"":"0")+seconde; }
|
else if (substr == 'ss') { result=result+(seconde<1||seconde>9?"":"0")+seconde; }
|
||||||
else { result=result+substr; }
|
else { result=result+substr; }
|
||||||
|
|
||||||
i+=substr.length;
|
i+=substr.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
//alert(result);
|
//alert(result);
|
||||||
@ -461,50 +461,50 @@ function formatDate(date,format)
|
|||||||
|
|
||||||
|
|
||||||
/*=================================================================
|
/*=================================================================
|
||||||
Function: getDateFromFormat(date_string, format_string)
|
Function: getDateFromFormat(date_string, format_string)
|
||||||
Purpose: This function takes a date string and a format string.
|
Purpose: This function takes a date string and a format string.
|
||||||
It parses the date string with format and it returns
|
It parses the date string with format and it returns
|
||||||
the date as a javascript Date() object.
|
the date as a javascript Date() object.
|
||||||
If date does not match format, it returns 0.
|
If date does not match format, it returns 0.
|
||||||
The format string can use the following tags:
|
The format string can use the following tags:
|
||||||
Field | Tags
|
Field | Tags
|
||||||
-------------+-------------------------------
|
-------------+-------------------------------
|
||||||
Year | yyyy (4 digits), yy (2 digits)
|
Year | yyyy (4 digits), yy (2 digits)
|
||||||
Month | MM (2 digits)
|
Month | MM (2 digits)
|
||||||
Day of Month | dd (2 digits)
|
Day of Month | dd (2 digits)
|
||||||
Hour (1-12) | hh (2 digits)
|
Hour (1-12) | hh (2 digits)
|
||||||
Hour (0-23) | HH (2 digits)
|
Hour (0-23) | HH (2 digits)
|
||||||
Minute | mm (2 digits)
|
Minute | mm (2 digits)
|
||||||
Second | ss (2 digits)
|
Second | ss (2 digits)
|
||||||
Author: Laurent Destailleur
|
Author: Laurent Destailleur
|
||||||
Licence: GPL
|
Licence: GPL
|
||||||
==================================================================*/
|
==================================================================*/
|
||||||
function getDateFromFormat(val,format)
|
function getDateFromFormat(val,format)
|
||||||
{
|
{
|
||||||
//alert('getDateFromFormat val='+val+' format='+format);
|
//alert('getDateFromFormat val='+val+' format='+format);
|
||||||
|
|
||||||
// Force parametres en chaine
|
// Force parametres en chaine
|
||||||
val=val+"";
|
val=val+"";
|
||||||
format=format+"";
|
format=format+"";
|
||||||
|
|
||||||
var now=new Date();
|
var now=new Date();
|
||||||
var year=now.getYear(); if (year.length < 4) { year=""+(year-0+1900); }
|
var year=now.getYear(); if (year.length < 4) { year=""+(year-0+1900); }
|
||||||
var month=now.getMonth()+1;
|
var month=now.getMonth()+1;
|
||||||
var day=now.getDate();
|
var day=now.getDate();
|
||||||
var hour=now.getHours();
|
var hour=now.getHours();
|
||||||
var minute=now.getMinutes();
|
var minute=now.getMinutes();
|
||||||
var seconde=now.getSeconds();
|
var seconde=now.getSeconds();
|
||||||
|
|
||||||
var i=0;
|
var i=0;
|
||||||
while (i < format.length)
|
while (i < format.length)
|
||||||
{
|
{
|
||||||
c=format.charAt(i); // Recupere char du format
|
c=format.charAt(i); // Recupere char du format
|
||||||
substr="";
|
substr="";
|
||||||
j=i;
|
j=i;
|
||||||
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques
|
while ((format.charAt(j)==c) && (j < format.length)) // Recupere char successif identiques
|
||||||
{
|
{
|
||||||
substr += format.charAt(j++);
|
substr += format.charAt(j++);
|
||||||
}
|
}
|
||||||
|
|
||||||
//alert('substr='+substr);
|
//alert('substr='+substr);
|
||||||
if (substr == "yyyy") year=getIntegerInString(val,i,4,4);
|
if (substr == "yyyy") year=getIntegerInString(val,i,4,4);
|
||||||
@ -521,49 +521,49 @@ function getDateFromFormat(val,format)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if format param are ok
|
// Check if format param are ok
|
||||||
if (year==null||year<1) { return 0; }
|
if (year==null||year<1) { return 0; }
|
||||||
if (month==null||(month<1)||(month>12)) { return 0; }
|
if (month==null||(month<1)||(month>12)) { return 0; }
|
||||||
if (day==null||(day<1)||(day>31)) { return 0; }
|
if (day==null||(day<1)||(day>31)) { return 0; }
|
||||||
if (hour==null||(hour<0)||(hour>24)) { return 0; }
|
if (hour==null||(hour<0)||(hour>24)) { return 0; }
|
||||||
if (minute==null||(minute<0)||(minute>60)) { return 0; }
|
if (minute==null||(minute<0)||(minute>60)) { return 0; }
|
||||||
if (seconde==null||(seconde<0)||(seconde>60)) { return 0; }
|
if (seconde==null||(seconde<0)||(seconde>60)) { return 0; }
|
||||||
|
|
||||||
//alert(year+' '+month+' '+day+' '+hour+' '+minute+' '+seconde);
|
//alert(year+' '+month+' '+day+' '+hour+' '+minute+' '+seconde);
|
||||||
var newdate=new Date(year,month-1,day,hour,minute,seconde);
|
var newdate=new Date(year,month-1,day,hour,minute,seconde);
|
||||||
|
|
||||||
return newdate;
|
return newdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*=================================================================
|
/*=================================================================
|
||||||
Function: stringIsInteger(string)
|
Function: stringIsInteger(string)
|
||||||
Purpose: Return true if string is an integer
|
Purpose: Return true if string is an integer
|
||||||
==================================================================*/
|
==================================================================*/
|
||||||
function stringIsInteger(str)
|
function stringIsInteger(str)
|
||||||
{
|
{
|
||||||
var digits="1234567890";
|
var digits="1234567890";
|
||||||
for (var i=0; i < str.length; i++)
|
for (var i=0; i < str.length; i++)
|
||||||
{
|
{
|
||||||
if (digits.indexOf(str.charAt(i))==-1)
|
if (digits.indexOf(str.charAt(i))==-1)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*=================================================================
|
/*=================================================================
|
||||||
Function: getIntegerInString(string,pos,minlength,maxlength)
|
Function: getIntegerInString(string,pos,minlength,maxlength)
|
||||||
Purpose: Return part of string from position i that is integer
|
Purpose: Return part of string from position i that is integer
|
||||||
==================================================================*/
|
==================================================================*/
|
||||||
function getIntegerInString(str,i,minlength,maxlength)
|
function getIntegerInString(str,i,minlength,maxlength)
|
||||||
{
|
{
|
||||||
for (var x=maxlength; x>=minlength; x--)
|
for (var x=maxlength; x>=minlength; x--)
|
||||||
{
|
{
|
||||||
var substr=str.substring(i,i+x);
|
var substr=str.substring(i,i+x);
|
||||||
if (substr.length < minlength) { return null; }
|
if (substr.length < minlength) { return null; }
|
||||||
if (stringIsInteger(substr)) { return substr; }
|
if (stringIsInteger(substr)) { return substr; }
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -592,3 +592,21 @@ function newpopup(url,title) {
|
|||||||
fen=window.open(tmp,title,wfeatures);
|
fen=window.open(tmp,title,wfeatures);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*=================================================================
|
||||||
|
Purpose: Récupère l'id d'une autcompletion Ajax
|
||||||
|
Input: field,item
|
||||||
|
Author: Regis Houssin
|
||||||
|
Licence: GPL
|
||||||
|
==================================================================*/
|
||||||
|
function ac_return(field, item){
|
||||||
|
// on met en place l'expression régulière
|
||||||
|
var regex = new RegExp('[0123456789]*-idcache', 'i');
|
||||||
|
// on l'applique au contenu
|
||||||
|
var idCache = regex.exec($(item).innerHTML);
|
||||||
|
//on récupère l'id
|
||||||
|
id = idCache[0].replace('-idcache', '');
|
||||||
|
// et on l'affecte au champ caché
|
||||||
|
$(field.name+'_id').value = id;
|
||||||
|
}
|
||||||
@ -380,6 +380,7 @@ if ($_POST["getcustomercode"] || $_POST["getsuppliercode"] ||
|
|||||||
|
|
||||||
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
|
print '<tr><td width="25%">'.$langs->trans('Country').'</td><td colspan="3">';
|
||||||
$form->select_pays($soc->pays_id,'pays_id',$conf->use_javascript?' onChange="autofilltownfromzip_save_refresh_create()"':'');
|
$form->select_pays($soc->pays_id,'pays_id',$conf->use_javascript?' onChange="autofilltownfromzip_save_refresh_create()"':'');
|
||||||
|
if ($conf->use_javascript && $conf->use_javascript) print '<div id="hint"></div>';//utile pour afficher la recherche des pays avec ajax
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
|
print '<tr><td>'.$langs->trans('State').'</td><td colspan="3">';
|
||||||
|
|||||||
@ -1044,3 +1044,32 @@ td.hidden {
|
|||||||
td.alerte {
|
td.alerte {
|
||||||
background: #FF99A9;
|
background: #FF99A9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ============================================================================== */
|
||||||
|
/* Liste déroulante de l'autocompletion Ajax */
|
||||||
|
/* ============================================================================== */
|
||||||
|
|
||||||
|
div.autocomplete {
|
||||||
|
position:absolute;
|
||||||
|
width:250px;
|
||||||
|
background-color:white;
|
||||||
|
border:1px solid #888;
|
||||||
|
margin:0px;
|
||||||
|
padding:0px;
|
||||||
|
}
|
||||||
|
div.autocomplete ul {
|
||||||
|
list-style-type:none;
|
||||||
|
margin:0px;
|
||||||
|
padding:0px;
|
||||||
|
}
|
||||||
|
div.autocomplete ul li.selected { background-color: #ffb;}
|
||||||
|
div.autocomplete ul li {
|
||||||
|
list-style-type:none;
|
||||||
|
display:block;
|
||||||
|
margin:0;
|
||||||
|
padding:2px;
|
||||||
|
height:16px;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user