I am seeing a weird behavior when I have a multi select and use the keyboard to select an item. If I use the mouse to select the items and get them as a string array, it seems to work. If I choose one item using the mouse, it also seems to work, and i get a String [] with one value in it. If I use the keyboard and select using the keyboard the value seems to be a String and if I try to get it as a String array, it gives me the name of the value parsed. below is sample code that illustrates the behavior.
If I start editing new, select Manufacturing as the product, check with my mouse Design Development and Qa. Then i click my See dept value button and i see [Design ,Development ,QA ,] which is what i would expect
If I change my dept selection to just design and then i click my See dept value button and i see [Design ,] which is also what i would expect
If I clear all the values and the start typing a D in the field, to point where is goes through the D options and selects them, like a normal select item. i leave it on Development, click on see dept value and I get [D ,e ,v ,e ,l ,o ,p ,m ,e ,n ,t ,]
Is there anyway to avoid this happening? Is there something I am missing that would easily correct this?
Thank you.
VLayout layout = new VLayout();
final ListGrid grid = new ListGrid();
Button button = new Button();
button.setTitle("Start Editing new Row");
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
grid.startEditingNew();
}
});
layout.addMember(button);
final Map<String, String[]> departments = new HashMap<String, String[]>();
departments.put("Marketing", new String[]{"Advertising", "Community Relations"});
departments.put("Sales", new String[]{"Channel Sales", "Direct Sales"});
departments.put("Manufacturing", new String[]{"Design", "Development", "QA"});
departments.put("Services", new String[]{"Support", "Consulting"});
grid.setWidth100();
grid.setHeight100();
grid.setHeaderHeight(60);
grid.setAlternateRecordStyles(true);
grid.setShowSortNumerals(false);
grid.setFilterOnKeypress(true);
grid.setModalEditing(true);
grid.setEditEvent(ListGridEditEvent.CLICK);
grid.setAutoFetchData(true);
grid.setEditByCell(true);
grid.setValidateOnChange(false);
grid.setCanReorderRecords(true);
grid.setShowAllRecords(true);
grid.setAutoSaveEdits(true);
ListGridField product = new ListGridField("product", "Product");
product.setType(ListGridFieldType.TEXT);
product.setCanEdit(true);
product.setValueMap("Marketing", "Sales", "Manufacturing", "Services");
SelectItem deptSelect = new SelectItem();
deptSelect.setAddUnknownValues(false);
deptSelect.setMultipleAppearance(MultipleAppearance.PICKLIST);
deptSelect.setMultiple(true);
ListGridField dept = new ListGridField("dept", "Department");
dept.setType(ListGridFieldType.TEXT);
dept.setCanEdit(true);
dept.setMultiple(true);
dept.setEditorValueMapFunction(new EditorValueMapFunction()
{
public Map getEditorValueMap(Map values, ListGridField field, ListGrid grid)
{
Map<String, String> valueMap = new HashMap<String, String>();
if (null != values.get("product"))
{
String product = values.get("product").toString();
String [] depts = departments.get(product);
for (int i = 0; i < depts.length; i++)
{
valueMap.put(depts[i], depts[i]);
}
}
return valueMap;
}
});
dept.setEditorProperties(deptSelect);
grid.setFields(product, dept);
layout.addMember(grid);
Button valueB = new Button();
valueB.setTitle("See dept value");
valueB.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
String values = "[";
for (String val: grid.getEditedRecord(0).getAttributeAsStringArray("dept"))
{
values += val + " ,";
}
values += "]";
SC.say(values);
}
});
layout.addMember(valueB);
If I start editing new, select Manufacturing as the product, check with my mouse Design Development and Qa. Then i click my See dept value button and i see [Design ,Development ,QA ,] which is what i would expect
If I change my dept selection to just design and then i click my See dept value button and i see [Design ,] which is also what i would expect
If I clear all the values and the start typing a D in the field, to point where is goes through the D options and selects them, like a normal select item. i leave it on Development, click on see dept value and I get [D ,e ,v ,e ,l ,o ,p ,m ,e ,n ,t ,]
Is there anyway to avoid this happening? Is there something I am missing that would easily correct this?
Thank you.
VLayout layout = new VLayout();
final ListGrid grid = new ListGrid();
Button button = new Button();
button.setTitle("Start Editing new Row");
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
grid.startEditingNew();
}
});
layout.addMember(button);
final Map<String, String[]> departments = new HashMap<String, String[]>();
departments.put("Marketing", new String[]{"Advertising", "Community Relations"});
departments.put("Sales", new String[]{"Channel Sales", "Direct Sales"});
departments.put("Manufacturing", new String[]{"Design", "Development", "QA"});
departments.put("Services", new String[]{"Support", "Consulting"});
grid.setWidth100();
grid.setHeight100();
grid.setHeaderHeight(60);
grid.setAlternateRecordStyles(true);
grid.setShowSortNumerals(false);
grid.setFilterOnKeypress(true);
grid.setModalEditing(true);
grid.setEditEvent(ListGridEditEvent.CLICK);
grid.setAutoFetchData(true);
grid.setEditByCell(true);
grid.setValidateOnChange(false);
grid.setCanReorderRecords(true);
grid.setShowAllRecords(true);
grid.setAutoSaveEdits(true);
ListGridField product = new ListGridField("product", "Product");
product.setType(ListGridFieldType.TEXT);
product.setCanEdit(true);
product.setValueMap("Marketing", "Sales", "Manufacturing", "Services");
SelectItem deptSelect = new SelectItem();
deptSelect.setAddUnknownValues(false);
deptSelect.setMultipleAppearance(MultipleAppearance.PICKLIST);
deptSelect.setMultiple(true);
ListGridField dept = new ListGridField("dept", "Department");
dept.setType(ListGridFieldType.TEXT);
dept.setCanEdit(true);
dept.setMultiple(true);
dept.setEditorValueMapFunction(new EditorValueMapFunction()
{
public Map getEditorValueMap(Map values, ListGridField field, ListGrid grid)
{
Map<String, String> valueMap = new HashMap<String, String>();
if (null != values.get("product"))
{
String product = values.get("product").toString();
String [] depts = departments.get(product);
for (int i = 0; i < depts.length; i++)
{
valueMap.put(depts[i], depts[i]);
}
}
return valueMap;
}
});
dept.setEditorProperties(deptSelect);
grid.setFields(product, dept);
layout.addMember(grid);
Button valueB = new Button();
valueB.setTitle("See dept value");
valueB.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event)
{
String values = "[";
for (String val: grid.getEditedRecord(0).getAttributeAsStringArray("dept"))
{
values += val + " ,";
}
values += "]";
SC.say(values);
}
});
layout.addMember(valueB);
Comment