Input with autocomplete

Develop and Deploy Cross-Browser Web Apps .

Input with autocomplete

Postby sedrok » Wed Jun 04, 2014 3:03 pm

Input with autocomplete

If you can improve this code please post here or send me email.

client code:
javascript code
// The default code is a com class (inherited from xui.Com)
Class('App', 'xui.Com',{
// Ensure that all the value of "key/value pair" does not refer to external variables
Instance:{
// To initialize instance(e.g. properties)
initialize : function(){
// To determine whether or not the com will be destroyed, when the first UI control be destroyed
this.autoDestroy = true;
// To initialize properties
this.properties = {};
},
// To initialize internal components (mostly UI controls)
// *** If you're not a skilled, dont modify this function manually ***
iniComponents : function(){
// [[Code created by CrossUI RAD Tools
var host=this, children=[], append=function(child){children.push(child.get(0));};

append((new xui.UI.List())
.setHost(host,"ctl_list1")
.setDirtyMark(false)
.setLeft(160)
.setTop(210)
.setWidth(370)
.setValue("a")
.onItemSelected("_ctl_list1_onitemselected")
);

append((new xui.UI.Input())
.setHost(host,"ctl_input1")
.setDirtyMark(false)
.setLeft(160)
.setTop(190)
.setWidth(370)
.setDynCheck(true)
.onChange("_ctl_input1_onchange")
);

return children;
// ]]Code created by CrossUI RAD Tools
},
// Give a chance to load other com
iniExComs : function(com, threadid){
},
// Give a chance to determine which UI controls will be appended to parent container
customAppend : function(parent, subId, left, top){
// "return false" will cause all the internal UI controls will be added to the parent panel
return false;
},
// This instance's events
events : {},

_ctl_input1_onchange:function (profile,oldValue,newValue){
var ns = this, uictrl = profile.boxing();
if(newValue.length > 3) {

xui.Ajax.method = 'POST';
xui.Ajax("getlogin.php",{name : ns.ctl_input1.getValue()},function(rsp){
ns.ctl_list1.setItems(rsp);
},function(errMsg){
xui.alert(errMsg);
}).start();

}
},
_ctl_list1_onitemselected:function (profile,item,e,src,type){
var ns = this, uictrl = profile.boxing();
xui.message(item.id);
}
}
});


Server code PHP (Example with LDAP)
php code
<?php
include "req.php";

if(!req(Array('name'))) die('parameters not set!');

// connect to ldap server
$ldapconn = @ldap_connect(".....")
or die("Could not connect to LDAP server.");

if ($ldapconn) {

// binding anonymously
$ldapbind = @ldap_bind($ldapconn ,'user', 'password');

if (!$ldapbind) {
echo "['LDAP bind failed...']";
}


$sr = @ldap_search($ldapconn, "OU=...,DC=...,DC=...", "(cn=*". iconv('utf-8','cp1251',$_REQUEST['name']) ."*)");
if(!$sr) die('[{caption:"search fail",disabled:true}]');
$info = ldap_get_entries($ldapconn, $sr);

if($info['count']==0) die('[{caption:"not found",disabled:true}]');

echo "[";
for($i=0;$i<$info['count'];$i++) {
if(isset($info[$i]['samaccountname'])) {
echo ($i==0 ? "" : ",") . '{id: "' . addslashes(iconv('cp1251','utf-8',$info[$i]['samaccountname'][0])) . '", caption: "' . addslashes(iconv('cp1251','utf-8', $info[$i]['cn'][0])) . '"}';
}
}
echo "]";
}
?>
Attachments
screen1.jpg
screen1.jpg (29.4 KiB) Viewed 3304 times
sedrok
 
Posts: 26
Joined: Tue Jun 03, 2014 12:50 pm

Return to CrossUI for Web Apps

Who is online

Users browsing this forum: No registered users and 0 guests

cron