Ok, ya lo terminé, efectivamente hice un array con los datos de la consulta y luego los paso a js, uso un conjunto de funciones js muy bien escritas que encontré y le adapté un script que genera nuevos inputs.<br>Todo es para cargar ítems en una factura determinada.<br>
<br>Para los que alguna vez necesiten un autocompletar lo paso por acá, aunque pueda haber mejores este me pareció simple y liviano.<br><br><?php<br>//Funcion que convierte un array php en un array js<br>function php2js ($var) {<br>
<br> if (is_array($var)) {<br> $res = "[";<br> $array = array();<br> foreach ($var as $a_var) {<br> $array[] = php2js(trim($a_var));<br> }<br> return "[" . join(",", $array) . "]";<br>
}<br> elseif (is_bool($var)) {<br> return $var ? "true" : "false";<br> }<br> elseif (is_int($var) || is_integer($var) || is_double($var) || is_float($var)) {<br> return $var;<br>
}<br> elseif (is_string($var)) {<br> return "\"" . addslashes(stripslashes($var)) . "\"";<br> }<br><br> return FALSE;<br>}<br><br><b>ESTA SERÍA LA PARTE DE GENERAR LA CONSULTA Y PONERLA EN UN ARRAY</b><br>
<b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><br>
//init the SOAP Client<br>require("lib.php"); //API CASPIO<br>$wsdl = "<a href="https://b3.caspio.com/ws/api.asmx?wsdl">https://b3.caspio.com/ws/api.asmx?wsdl</a>";<br>$client = new SoapClient($wsdl);<br>
<br>//Armo el array con la consulta de los productos<br>$php_array = $client->SelectDataRaw("silveral", "administracion", "1kE9u58vu82HircT5", "Productos_visibles",<br>true, <br>
"Productos_Codigo, Productos_Descripcion",<br>"Productos_Codigo IS NOT NULL",<br>"Productos_Codigo ASC",<br>" - ", " ");<b><br></b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//</b><b>//<br>
<br></b>//Convierto el array php en array js<br>$js_array = php2js($php_array);<br>?><br><br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>"><br>
<html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>"><br><title>Carga Item Factura</title><br><head><br><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><br>
<script language="JavaScript" type="text/javascript"><br>function autoCompleteDB()<br>{<br> this.aNames=new Array();<br>}<br><br>autoCompleteDB.prototype.assignArray=function(aList)<br>{<br> this.aNames=aList;<br>
};<br><br>autoCompleteDB.prototype.getMatches=function(str,aList,maxSize)<br>{<br> /* debug */ //alert(maxSize+"ok getmatches");<br> var ctr=0;<br> for(var i in this.aNames)<br> {<br> if(this.aNames[i].toLowerCase().indexOf(str.toLowerCase())==0) /*looking for case insensitive matches */<br>
{<br> aList.push(this.aNames[i]);<br> ctr++;<br> }<br> if(ctr==(maxSize-1)) /* counter to limit no of matches to maxSize */<br> break;<br> }<br>};<br><br>function autoComplete(aNames,oText,oDiv,maxSize)<br>
{<br><br> this.oText=oText;<br> this.oDiv=oDiv;<br> this.maxSize=maxSize;<br> this.cur=-1;<br><br> <br> /*debug here */<br> //alert(oText+","+this.oDiv);<br> <br> this.db=new autoCompleteDB();<br>
this.db.assignArray(aNames);<br> <br> oText.onkeyup=this.keyUp;<br> oText.onkeydown=this.keyDown;<br> oText.autoComplete=this;<br> oText.onblur=this.hideSuggest;<br>}<br><br>autoComplete.prototype.hideSuggest=function()<br>
{<br> this.autoComplete.oDiv.style.visibility="hidden";<br>};<br><br>autoComplete.prototype.selectText=function(iStart,iEnd)<br>{<br> if(this.oText.createTextRange) /* For IE */<br> {<br> var oRange=this.oText.createTextRange();<br>
oRange.moveStart("character",iStart);<br> oRange.moveEnd("character",iEnd-this.oText.value.length);<br> oRange.select();<br> }<br> else if(this.oText.setSelectionRange) /* For Mozilla */<br>
{<br> this.oText.setSelectionRange(iStart,iEnd);<br> }<br> this.oText.focus();<br>};<br><br>autoComplete.prototype.textComplete=function(sFirstMatch)<br>{<br> if(this.oText.createTextRange || this.oText.setSelectionRange)<br>
{<br> var iStart=this.oText.value.length;<br> this.oText.value=sFirstMatch;<br> this.selectText(iStart,sFirstMatch.length);<br> }<br>};<br><br>autoComplete.prototype.keyDown=function(oEvent)<br>
{<br> oEvent=window.event || oEvent;<br> iKeyCode=oEvent.keyCode;<br><br> switch(iKeyCode)<br> {<br> case 38: //up arrow<br> this.autoComplete.moveUp();<br> break;<br> case 40: //down arrow<br>
this.autoComplete.moveDown();<br> break;<br> case 13: //return key<br> window.focus();<br> break;<br> }<br>};<br><br>autoComplete.prototype.moveDown=function()<br>{<br>
if(this.oDiv.childNodes.length>0 && this.cur<(this.oDiv.childNodes.length-1))<br> {<br> ++this.cur;<br> for(var i=0;i<this.oDiv.childNodes.length;i++)<br> {<br> if(i==this.cur)<br>
{<br> this.oDiv.childNodes[i].className="over";<br> this.oText.value=this.oDiv.childNodes[i].innerHTML;<br> }<br> else<br> {<br> this.oDiv.childNodes[i].className="";<br>
}<br> }<br> }<br>};<br><br>autoComplete.prototype.moveUp=function()<br>{<br> if(this.oDiv.childNodes.length>0 && this.cur>0)<br> {<br> --this.cur;<br> for(var i=0;i<this.oDiv.childNodes.length;i++)<br>
{<br> if(i==this.cur)<br> {<br> this.oDiv.childNodes[i].className="over";<br> this.oText.value=this.oDiv.childNodes[i].innerHTML;<br> }<br> else<br>
{<br> this.oDiv.childNodes[i].className="";<br> }<br> }<br> }<br>};<br><br>autoComplete.prototype.keyUp=function(oEvent)<br>{<br> oEvent=oEvent || window.event;<br>
var iKeyCode=oEvent.keyCode;<br> if(iKeyCode==8 || iKeyCode==46)<br> {<br> this.autoComplete.onTextChange(false); /* without autocomplete */<br> }<br> else if (iKeyCode < 32 || (iKeyCode >= 33 && iKeyCode <= 46) || (iKeyCode >= 112 && iKeyCode <= 123)) <br>
{<br> //ignore<br> } <br> else <br> {<br> this.autoComplete.onTextChange(true); /* with autocomplete */<br> }<br>};<br><br>autoComplete.prototype.positionSuggest=function() /* to calculate the appropriate poistion of the dropdown */<br>
{<br> var oNode=this.oText;<br> var x=0,y=oNode.offsetHeight;<br><br> while(oNode.offsetParent && oNode.offsetParent.tagName.toUpperCase() != 'BODY')<br> {<br> x+=oNode.offsetLeft;<br> y+=oNode.offsetTop;<br>
oNode=oNode.offsetParent;<br> }<br><br> x+=oNode.offsetLeft;<br> y+=oNode.offsetTop;<br><br> this.oDiv.style.top=y+"px";<br> this.oDiv.style.left=x+"px";<br>}<br><br>autoComplete.prototype.onTextChange=function(bTextComplete)<br>
{<br> var txt=this.oText.value;<br> var oThis=this;<br> this.cur=-1;<br> <br> if(txt.length>0)<br> {<br> while(this.oDiv.hasChildNodes())<br> this.oDiv.removeChild(this.oDiv.firstChild);<br>
<br> var aStr=new Array();<br> this.db.getMatches(txt,aStr,this.maxSize);<br> if(!aStr.length) {this.hideSuggest ;return}<br> if(bTextComplete) this.textComplete(aStr[0]);<br> this.positionSuggest();<br>
<br> for(i in aStr)<br> {<br> var oNew=document.createElement('div');<br> this.oDiv.appendChild(oNew);<br> oNew.onmouseover=<br> oNew.onmouseout=<br>
oNew.onmousedown=function(oEvent)<br> {<br> oEvent=window.event || oEvent;<br> oSrcDiv=oEvent.target || oEvent.srcElement;<br><br> //debug :window.status=oEvent.type;<br>
if(oEvent.type=="mousedown")<br> {<br> oThis.oText.value=this.innerHTML;<br> }<br> else if(oEvent.type=="mouseover")<br> {<br>
this.className="over";<br> }<br> else if(oEvent.type=="mouseout")<br> {<br> this.className="";<br> }<br>
else<br> {<br> this.oText.focus();<br> }<br> };<br> oNew.innerHTML=aStr[i];<br> }<br> <br> this.oDiv.style.visibility="visible";<br>
}<br> else<br> {<br> this.oDiv.innerHTML="";<br> this.oDiv.style.visibility="hidden";<br> }<br>};<br><br>/*function createAutoComplete()<br>{<br> var aNames = <?php //print_r($js_array); ?>;<br>
new autoComplete(aNames,document.getElementById('txt'),document.getElementById('suggest'),20);<br>}<br>*/<br>function createAutoComplete1(txt_input, suggest_div)<br>{<br> var aNames = <?php print_r($js_array); ?>;<br>
new autoComplete(aNames,document.getElementById(txt_input),document.getElementById(suggest_div),20);<br>}<br><br>/*<![CDATA[*/<br>var c=1;<br>function newInput()<br>{<br> //Create DIV<br> var div = document.createElement('div');<br>
<a href="http://div.id">div.id</a> = "div_" + c;<br> document.f1.appendChild(div);<br> //Input TEXT<br> var inpt = document.createElement('input');<br> inpt.type="text";<br> <a href="http://inpt.name">inpt.name</a>="input_" + c;<br>
<a href="http://inpt.id">inpt.id</a>="txt_" + c;<br> inpt.setAttribute ('autocomplete', 'off');<br> inpt.setAttribute ( 'style', "border:#000000 1px solid; width:250px;");<br>
div.appendChild(inpt);<br> //Link +<br> div.innerHTML += "<a style='text-decoration:none' href='#' onclick='javascript:newInput()'> [+] </a>";<br> //Link -<br> div.innerHTML += "<a style='text-decoration:none' href='#' onclick='javascript:removeInput(\"div_" + c + "\")'> [-] </a><br>";<br>
//Create DIV SUGGEST<br> var divS = document.createElement('div');<br> divS.id = "suggest_" + c;<br> divS.setAttribute ( 'style', "visibility:hidden; border:#000000 1px solid; width:auto;");<br>
divS.setAttribute ( 'class', "suggest");<br> div.appendChild(divS);<br> createAutoComplete1(<a href="http://inpt.id">inpt.id</a>, divS.id);<br> c += 1;<br><br>}<br>function removeInput(id)<br>
{<br> if(cantElementForm() > 1)<br> document.f1.removeChild(document.getElementById(id));<br> else<br> alert ("ATENCIÓN!\nNo se puede borrar el único elemento de carga");<br>}<br><br>function cantElementForm()<br>
{<br> return document.forms.item(0).elements.length;<br>}<br>/*]]>*/<br></script><br><style type="text/css" media="all"><br>.suggest{<br> position:absolute;<br> background:#fff;<br>
width:200px;<br> }<br><br>.suggest div{<br> background:#fff;<br> color:#000;<br> padding-left:4px;<br> cursor:hand;<br> text-align:left;<br> }<br><br>.suggest div.over{<br> color:#fff;<br> background:#000;<br>
}<br></style><br><br><script type="text/javascript"><br><br></script><br><br></head><br><br><body onLoad="newInput(); createAutoComplete();"><br><?php<br> //echo "Factura Nro.: ".$_GET['FacturaID'];<br>
echo "Factura Nro.: ";<br>?><br><br /><br><div><br> <form action="#" method="get" name="f1" id="f1" autocomplete=off><br><!-- <div id="div_0"><br>
<input type="text" name="searchField" id="txt_0" style="border:#000000 1px solid;width:150px;" autocomplete=off><br> <a href="#" onclick="javascript:newInput()" style="text-decoration:none"> [+] </a><br><br>
<div class="suggest" id="suggest_0" style="visibility:hidden;border:#000000 1px solid;width:150px;"></div><br> </div><br>--> </form><br></div><br>
<br><br></body><br></html><br>