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
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Two fields auto completion
-
- Posts: 101
- Joined: Mon Mar 26, 2018 5:57 pm
Two fields auto completion
You do not have the required permissions to view the files attached to this post.
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Two fields auto completion
Initialize autocomplete for both "prenom" and "nom" and use the split() method to split up the prenom / nom into separate chunks.
Untested:
Untested:
Code: Select all
function initAutoComplete(param) {
$('#contact_prenom').autocomplete({
source: JSON.parse(param),
minLength: 1,
select: function(event, ui) {
$(event.target).val(ui.item.value.split(',')[0]).change(); // prenom
$('#contact_nom').val(ui.item.value.split(',')[1]).change(); // nom
}
});
$('#contact_nom').autocomplete({
source: JSON.parse(param),
minLength: 1,
select: function(event, ui) {
$(event.target).val(ui.item.value.split(',')[1]).change(); // nom
$('#contact_prenom').val(ui.item.value.split(',')[0]).change(); // prenom
}
});
}
-
- Posts: 101
- Joined: Mon Mar 26, 2018 5:57 pm
Re: Two fields auto completion
Thanks toms. I added this JS code to the form:
But when I test it, when I click on the offered auto completion, nothing happens:
Code: Select all
function initAutoComplete(param) {
$('#contact_prenom').autocomplete({
source: JSON.parse(param),
minLength: 1,
select: function(event, ui) {
$(event.target).val(ui.item.value.split(',')[0]).change();
$('#contact_nom').val(ui.item.value.split(',')[1]).change();
}
});
$('#contact_nom').autocomplete({
source: JSON.parse(param),
minLength: 1,
select: function(event, ui) {
$(event.target).val(ui.item.value.split(',')[1]).change();
$('#contact_prenom').val(ui.item.value.split(',')[0]).change();
}
});
}
function nuLoadEdit() {
nuAjax('ContactNomAutoCompletion','initAutoComplete');
}
You do not have the required permissions to view the files attached to this post.
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Two fields auto completion
Give this a try:
Code: Select all
function initAutoComplete(param) {
function setNames(ui) {
setTimeout(function() {
var selectVal = ui.item.value.toString();
var a = selectVal.split(',')
$('#contact_prenom').val(a[0]).change();
$('#contact_nom').val(a[1]).change();
}, 0);
}
$('#contact_prenom').autocomplete({
source: JSON.parse(param),
minLength: 1,
select: function(event, ui) {
setNames(ui);
}
});
$('#contact_nom').autocomplete({
source: JSON.parse(param),
minLength: 1,
select: function(event, ui) {
setNames(ui);
}
});
}
Last edited by Anonymous on Thu Apr 26, 2018 5:14 pm, edited 1 time in total.
-
- Posts: 101
- Joined: Mon Mar 26, 2018 5:57 pm
Re: Two fields auto completion
It works, thanks !
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23