Two fields auto completion
Posted: Thu Apr 26, 2018 11:41 am
Hey,
I already got an answer here from toms: https://forums.nubuilder.cloud/viewtopic.php?f=19&t=9459 regarding field auto completion. It works perfectly.
Now I would like to do something a bit trickier:
when entering a person, I would like to have a field auto completion activated on both fields first name and last name, which looks for both first name and last name at the same time. So far here is the procedure I got:
$sql = "SELECT contact_prenom, contact_nom FROM contact";
$retval = nuRunQuery($sql);
$row_arr = array();
$return_arr = array();
if($retval){
while($row = db_fetch_row($retval)) {
$row_arr['value']= $row;
array_push($return_arr,$row_arr);
}
$nuParameters = json_encode($return_arr);
}
And the JS:
function initAutoComplete(param) {
$("#contact_prenom").autocomplete({
source: JSON.parse(param),
minLength: 1,
select: function(event, ui) {
$(event.target).val(ui.item.value).change();
}
});
}
function nuLoadEdit() {
nuAjax('ContactNomAutoCompletion','initAutoComplete');
}
And the results: But when I click on it, it adds both the first name and last name in the field first name. I would like to seperate, after clicking only, the first name and last name in the two fields. How can I do it ?
Thanks a lot,
Marc
I already got an answer here from toms: https://forums.nubuilder.cloud/viewtopic.php?f=19&t=9459 regarding field auto completion. It works perfectly.
Now I would like to do something a bit trickier:
when entering a person, I would like to have a field auto completion activated on both fields first name and last name, which looks for both first name and last name at the same time. So far here is the procedure I got:
$sql = "SELECT contact_prenom, contact_nom FROM contact";
$retval = nuRunQuery($sql);
$row_arr = array();
$return_arr = array();
if($retval){
while($row = db_fetch_row($retval)) {
$row_arr['value']= $row;
array_push($return_arr,$row_arr);
}
$nuParameters = json_encode($return_arr);
}
And the JS:
function initAutoComplete(param) {
$("#contact_prenom").autocomplete({
source: JSON.parse(param),
minLength: 1,
select: function(event, ui) {
$(event.target).val(ui.item.value).change();
}
});
}
function nuLoadEdit() {
nuAjax('ContactNomAutoCompletion','initAutoComplete');
}
And the results: But when I click on it, it adds both the first name and last name in the field first name. I would like to seperate, after clicking only, the first name and last name in the two fields. How can I do it ?
Thanks a lot,
Marc