Page 1 of 1

Dynamic Auto Complete with UDF

Posted: Tue Oct 16, 2018 12:27 pm
by mwalter
I'm trying to add dynamic auto complete to a text box.
I created a UDF that accepts two parameters. I added this code to the onkeyup event of the text box.

Code: Select all

debugger;
var loc = get("ddLocation");
var chars = get("txtItemLookup");
var url = "http://myIBMI:8080/profoundui/universal/getTransferItems?chars=" + 
         encodeURIComponent(chars) + "&loc=" + 
         encodeURIComponent(loc);
applyProperty("txtItemLookup","choices url", url);
applyProperty("txtItemLookup","field type","textbox");
If I plug the URL into a browser I get the following JSON, which i verified correct using JSONLINT.

Code: Select all

{
	"success": true,
	"response": {
		"colWidths": [13,
		30],
		"results": [{
			"item": "998300",
			"desc": "TOYOTA MULTI 2000 & UP S/DDIN"
		},
		{
			"item": "90580",
			"desc": "EARPLUGS,4PR,DISPOSABLE"
		},
		{
			"item": "993304",
			"desc": "BUICK TERRAZA,SATURN RELAY,PON"
		},
		{
			"item": "911R",
			"desc": "FIRST ALERT, BATTERY OPERATED"
		},
		{
			"item": "90716",
			"desc": "3M TEKKPROTECT REUSE CORDED EA"
		}]
	}
}
However, when I run the program, it doesn't seem that the code is firing.

Can I do this like this, or should I be using some other method?

Re: Dynamic Auto Complete with UDF

Posted: Fri Oct 19, 2018 10:11 am
by Emily
Hi mwalter,

Looking at the code that you're using, your problem may be caused by the URL that you're using for the 'choices URL' property. In 'choices URL', you do not need to include the entire URL. So, in your example below, you do not need to include 'http://myIBMI:8080', just the part of the URL that starts with /profoundui/.

Could you try changing this in your 'onkeyup' event and see if this solves the problem you're having?

Re: Dynamic Auto Complete with UDF

Posted: Mon Oct 22, 2018 2:38 pm
by mwalter
Still not working.

Re: Dynamic Auto Complete with UDF

Posted: Mon Oct 22, 2018 3:40 pm
by Scott Klement
I'm not understanding when you are running this JavaScript code. You say "onkeyup of the text box" -- surely you don't mean the same textbox that has autocomplete configured for it, as that doesn't make any sense. (You'd be asking it to wipe out everything you've done so far when you ask it to re-render the box. You'd haveto type AGAIN after changing this before the autocomplete would run with the new parameters, but since you'd wipe it out again as soon as they typed again... it'd never work... nor does it make sense, since as far as I can tell the criteria doesn't change when you type in the autocomplete box, why would you want to reset everything?)

Do you mean that your "ddLocation" or "txtItemLookup" are textboxes and you are doing it in the onkeyup of those?

Since you seem to be asking the community to troubleshoot your application for you, it'd help an awful lot if you'd provide a code sample we can load and run to reproduce the problem.

Re: Dynamic Auto Complete with UDF

Posted: Tue Oct 23, 2018 5:01 pm
by mwalter
Basically, what I'm trying to do, is replicate an application I saw you develop at the Plus conference last year, when you were doing the item number lookup. I tried to find it, but I can't seem to locate the video.

It sent an ajax call to a UDF program for each keyup event to narrow down your search. The reason I wanted to do it this way, and not just use the the database driven autocomplete is that the criteria that returns the data is very dynamic.

Does this make sense?

Re: Dynamic Auto Complete with UDF

Posted: Wed Oct 24, 2018 10:28 am
by mwalter
I got around the problem by creating a view and creating selection criteria on that in the Database Driven Auto Complete.