Skip to main content

poputing another textbox based on option selected from a yahoo autocomplete

4 replies [Last post]
vinayajax
Offline
Joined: 2008-07-21

Hi All,

I am new at jmaki and confronting a problem.
My problem goes like this I have a yahoo autocomplete textbox and a normal textbox in a jsp page.I also have a database table with two column.First column contains some description and second contains some code.Autocomplete textbox's options come from first column of table.

Now i want as soon as user types something in autocomplete textbox dropdown comes and when user selects an option corresponding code from second column of table should dynamically get populated in second textbox.Second textbox can be normal textbox or jmaki textbox widget.

I tried but could not find which event yahoo autocomplete generates and don't know the default topic for yahoo autocomplete.Event i tried user defined topic but my handler in glue.js could not be invoked.

I am dynamically creating yahoo autocomplete in javascript file.
javascript file :

factory.loadWidget(
{ widget : {name : "yahoo.autocomplete" , service : "Data.jsp", pblish : "/vinay" }, container : someDiv});

glue.js

jmaki.subscribe("/vinay", function(args) {
var message = args.value;
alert("message : " + message);
});

Any help will be appreciated.

Vinay

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gmurray71
Offline
Joined: 2003-07-31

Hi vinay.

You almost got it.

The publish you give a widget is just the "base" for what is used for the publishes of the events.

An autocompleter will publish to:

"/vinay/onSelect" when something is selected.

So for your purposes you can have:

jmaki.subscribe("/vinay/onSelect", function(args) {
var message = args.value;
alert("message : " + message);
});

or:

jmaki.subscribe("/vinay/*", function(args) {
var message = args.value;
alert("message : " + message);
});

For all events.

Hope this helps.

-Greg

gmurray71
Offline
Joined: 2003-07-31

And if you ever wonder "what events are being published?" I suggest turning on the jMaki logger and publish / subscribe event logging.

do this in you glue.js with :

jmaki.debug = true;
jmaki.debugGlue = true;

or in the /resources/config.json add the top level property:

"debugLevel" : "all"

vinayajax
Offline
Joined: 2008-07-21

Thanks a lot Greg for your quick and kind attention.

I was trying almost same thing as you instructed.
In my jsp file

was missing.
That could be the reason subscriber function was not getting invoked.
Event my jmaki looger was disappearing after 2 screens.
Even that started coming after including script tag.

Now control is reaching to subscriber.
Now i need to fetch data from database in subscriber and populate adjoing textbox which i am working on.
Thanks again.

Vinay

vinayajax
Offline
Joined: 2008-07-21

Hi All,

One last thing remains in this problem.
When i use value attribute in order to populate autocomplete while dynamically loading autocomplete widget control reaches in subscriber of the topic.

factory.loadWidget(
{
widget : {uuid : "problem" + count_row, name : "yahoo.autocomplete" ,
value: [{label : 'Alabama', value : 'AL'},{label : 'Alaska', value : 'AK'},{label : 'California', value : 'CA'},{label : 'New York', value : 'NY', selected : true},{label : 'Texas', value : 'TX'}],
publish : "/yahoo/autocomplete" },
container : someDiv});

Instead when i use service attribute in order to populate autocomplete while dynamically loading autocomplete widget control does not reaches in subscriber of the topic.

factory.loadWidget(
{ widget : {uuid : "problem" + count_row, name : "yahoo.autocomplete" , service : "Data.jsp", publish : "/yahoo/autocomplete" },
container : someDiv});

In jsp file i am fetching data from database and providing to widget in XML format.
Excerpts frrom Data.jsp
<%
out.println("");
for (int i = 0; i < desc.size(); i++) {
final String state = (String)desc.get(i);
if (state.toLowerCase().startsWith(query)) {
out.println("");
out.println("" + state + "");
out.println("
");
}
}
out.println("
");
%>
I need to get data from database so i need to use service attribute. Loading of widget is done in javascript file so i can not use usebean tag in value attribute.

Any help, why control does not reach in subscriber with service attribute whereas it reaches in case of value attribute?