PDA

View Full Version : Problem with ComboBox and JSON



Yan26
2 Dec 2008, 8:40 PM
Hi,

First, I've been working with GXT for a while now and it's really great...

I'm curently having a problem involving ComboBox feeded with JSON.

I'm using GWT 1.2, on a Windows XP plaform, communicating with a Ruby on Rails server through JSON. I'm mainly using the hosted form for now but what I'm about to describe is also happening in Firefox, IE7 and Google Chrome...

You have a simple example bellow that reproduce the problem.

The ComboBox is, like I said, filled with a store using and HttpProxy and a JsonReader. My example use a MemoryProxy to keep it simple and easy to try by yourself.

This image shows what the problem is :

http://esynthese.com/images/aircraft.jpg

You see "Beech 18" partially selected, but in fact in the comboBox I typed "Twi" wanting to select "Twin Otter"...

The first item is always selected if I type in the comboBox, no matter what I type...


Here's the GXT code generating the problem describe here:



public void onModuleLoad() {
ModelType type = new ModelType();
type.root = "rows";
type.addField("id");
type.addField("name");

MemoryProxy proxy = new MemoryProxy("{\"rows\": [{\"name\": \"Beech 18\", \"id\": 1}, {\"name\": \"Cessna 172\", \"id\": 2}, {\"name\": \"Cessna 180\", \"id\": 3}, {\"name\": \"Cessna 182\", \"id\": 4}, {\"name\": \"Cessna 205\", \"id\": 5}, {\"name\": \"Cessna 206\", \"id\": 6}, {\"name\": \"Cessna 207\", \"id\": 7}, {\"name\": \"Cessna 208\", \"id\": 8}, {\"name\": \"Cessna Caravan\", \"id\": 9}, {\"name\": \"King Air 90\", \"id\": 10}, {\"name\": \"Piper Navajo PA-31\", \"id\": 11}, {\"name\": \"Twin Otter\", \"id\": 12}]}");
JsonReader reader = new JsonReader(type);
ListLoader listLoader = new BaseListLoader(proxy, reader);
ListStore aircraftStore = new ListStore(listLoader);

ComboBox aircraft = new ComboBox();
aircraft.setDisplayField("name");
aircraft.setMinChars(1);
aircraft.setStore(aircraftStore);
aircraft.setTypeAhead(true);
aircraft.setWidth(150);

ContentPanel panel = new ContentPanel();
panel.setHeight(150);
panel.setWidth(150);
panel.add(aircraft);

RootPanel.get().add(panel);
}



Thank you for you time, your help will be greatly appreciated..