Page 1 of 1

autocomplete using database

Posted: Fri Aug 27, 2010 6:12 am
by jgreen
I would like to use autocomplete to have the user key and select a name and then use the selected name to return the account number associated with the name to the screen. I have tried unsuccessfully. Is this possible? If so where can I find a step by step guide?

Thx.

I agree with others on this forum this is a GREAT product!

Re: autocomplete using database

Posted: Mon Aug 30, 2010 1:04 pm
by michael.mayer-oakes
New to the product myself but this appears to be done with the Database-Driven Auto-Complete functionality in the UI Visual Developer. It looks like you just give it a db file and option fields, so a name field and a ID field for example from the db file.

Re: autocomplete using database

Posted: Wed Sep 01, 2010 11:34 am
by David
Yes, this is certainly possible.

To enable this functionality, start with a textbox control. Set the "choices database file" to the desired file. At runtime, this file will be located using the current library list of the application's job.

Set the "choices options field" property to the desired field name from the file that you'd like the user to search on -- in this case the name field. There is a field selection button that you can use in this property to select the field from a listing of fields in the file.

Set the "choice values field" property to the field you'd like to return to the program for this field -- in this case the id field.

When set up this way, the user will see/search on the names as they type. The program will get the id value into the field which is bound to the textbox's "value" property when the screen is submitted to the server.

When the screen is redisplayed, you could have RPG code move the id value into another output field on the screen (through "value" property binding) so that the id can be seen on the screen also.

If you'd like to show the selected id value automatically before the screen submits, you can use the "onselect" event to call some JavaScript code to do this.

You could create an output field widget on the screen and assign a unique value to the "id" property.

You could then create a JavaScript function (for example "myFunction") and assign the name to the "onselect" property.

When the user makes a selection, the function will be called and the selected record will be passed in to the function.

The function would be written like this:

Code: Select all


function myFunction(record) {

  var outputField = document.getElementById("fieldId"); // case-sensitive "id" property of output field.

  outputField.innerHTML = record["fieldName"]; // name of "choice values" field.

}

For populating the id value into the output field on first screen load (for example in "edit" mode), you could use "value" property binding to move the id in from RPG.