Hi,
SC_SNAPSHOT-2011-03-21/EVAL Deployment
FireFox 3.6.15
I think that due to a recent fix, the following issue has (re)-appeared.
Repo-case:
Grid with inline editing, edit the row, press the icon.. enter a decimal value in the input field of the dialog that appears and press the button "OK".
Value from dialog box is not saved/set to the grid!
Post that might (and I stress 'might') have caused this issue to have re-appeared:
http://forums.smartclient.com/showthread.php?t=15871
I think the solution that was added for this post, was removed or changed:
http://forums.smartclient.com/showthread.php?t=12044
Here is my standalone test case:
SC_SNAPSHOT-2011-03-21/EVAL Deployment
FireFox 3.6.15
I think that due to a recent fix, the following issue has (re)-appeared.
Repo-case:
Grid with inline editing, edit the row, press the icon.. enter a decimal value in the input field of the dialog that appears and press the button "OK".
Value from dialog box is not saved/set to the grid!
Post that might (and I stress 'might') have caused this issue to have re-appeared:
http://forums.smartclient.com/showthread.php?t=15871
I think the solution that was added for this post, was removed or changed:
http://forums.smartclient.com/showthread.php?t=12044
Here is my standalone test case:
Code:
public class Standalone implements EntryPoint { private static Canvas masterPanel = null; public void onModuleLoad() { masterPanel = new Canvas(); masterPanel.setHeight100(); masterPanel.setWidth100(); masterPanel.setStyleName("pageBackground"); //background style from skin masterPanel.addChild(testCase3()); masterPanel.draw(); } public ListGrid testCase3() { DataSourceField myPercentField = new DataSourceField(); myPercentField.setName("percentageField"); myPercentField.setTitle("percentageField"); myPercentField.setType(new MyPercentageItem()); myPercentField.setEditorType(new MyPercentageEditor()); DataSource dataSource = new DataSource(); dataSource.setFields(myPercentField); dataSource.setClientOnly(true); //set the initial value JavaScriptObject jsObject = JSOHelper.createObject(); JSOHelper.setAttribute(jsObject, MyPercentageItem.FIELD_DOUBLE, new Double(5.89)); ListGridRecord[] result = new ListGridRecord[1]; result[0] = new ListGridRecord(); result[0].setAttribute("percentageField", jsObject); //the order list grid ListGrid ordersList = new ListGrid(); ordersList.setHeight(170); ordersList.setWidth(500); ordersList.setCanEdit(true); ordersList.setDataSource(dataSource); ordersList.setData(result); return ordersList; } public class MyPercentageItem extends SimpleType { public final static String FIELD_DOUBLE = "floatValue"; private NumberFormat formatter; public MyPercentageItem() { super("myPercentageItem", FieldType.ANY); formatter = NumberFormat.getFormat("0.00%"); this.setShortDisplayFormatter(new MyPercentageFormatter()); this.setNormalDisplayFormatter(new MyPercentageFormatter()); } public class MyPercentageFormatter implements SimpleTypeFormatter { public String format(Object value, DataClass field, DataBoundComponent component, Record record) { if (value == null) { return ""; } if (value instanceof JavaScriptObject) { SC.logWarn("formatValue called"); JavaScriptObject jsObject = (JavaScriptObject) value; Float floatValue = JSOHelper.getAttributeAsFloat(jsObject, MyPercentageItem.FIELD_DOUBLE); if(floatValue.floatValue() == Float.MIN_VALUE) return ""; return formatter.format(floatValue); } return value.toString(); } } } public class MyPercentageEditor extends TextItem { private NumberFormat formatter; private String dataFormat = "0.00%";//display format private Float floatValue; private static Dialog dialog; private static MyPercentageEditor currentEditor; public MyPercentageEditor() { super(); this.setChangeOnKeypress(false); this.setSelectOnFocus(true); this.setWidth("*"); FormItemIcon icon = new FormItemIcon(); icon.setSrc("[SKIN]/actions/edit.png"); icon.setTabIndex(-1); setIcons(icon); setShowIcons(true); addIconClickHandler(new IconClickHandler() { public void onIconClick(IconClickEvent event) { // get global coordinates of the clicked picker icon Rectangle iconRect = getIconPageRect(event.getIcon()); // lazily create the YesNoMaybe picker dialog the first time a yesNoMaybe editor is clicked if (MyPercentageEditor.dialog == null) { MyPercentageEditor.makeDialog(); } // remember what editor is active, so we can set its value from the picker dialog MyPercentageEditor.currentEditor = MyPercentageEditor.this; // show the picker dialog MyPercentageEditor.showDialog(EventHandler.getX(), EventHandler.getY()); } }); formatter = NumberFormat.getFormat(this.dataFormat); // link the formatter to the editor this.setEditorValueFormatter(new SilkPercentageValueFormatter()); this.setEditorValueParser(new SilkPercentageValueParser()); } public class SilkPercentageValueFormatter implements FormItemValueFormatter { public String formatValue(Object value, Record record, DynamicForm form, FormItem item) { if (value == null) { return ""; } if (value instanceof JavaScriptObject) { SC.logWarn("formatValue called"); JavaScriptObject jsObject = (JavaScriptObject) value; floatValue = JSOHelper.getAttributeAsFloat(jsObject, MyPercentageItem.FIELD_DOUBLE); if(floatValue.floatValue() == Float.MIN_VALUE) return ""; return formatter.format(floatValue);//show rounded decimals } return (String) value; } } public class SilkPercentageValueParser implements FormItemValueParser { public Object parseValue(String value, DynamicForm form, FormItem item) { JavaScriptObject jsObject = null; if (item.getValue() instanceof JavaScriptObject) { jsObject = (JavaScriptObject) item.getValue(); } Float floatValue = Float.MIN_VALUE; try{ //onBlur, store the value as entered by the user... //check if it contains a percentage, if so => divide by 100 and store! String tmp = value.replaceAll("%", ""); if(!tmp.equals(value)){//did the original value contain '%' floatValue = Float.parseFloat(tmp) / 100; } else{ floatValue = Float.parseFloat(value); } }catch(NumberFormatException ex){ //could not parse input => return MIN_VALUE } JavaScriptObject newJsObject = JSOHelper.createObject(); JSOHelper.setAttribute(newJsObject, MyPercentageItem.FIELD_DOUBLE, floatValue); return newJsObject; } } private static void makeDialog() { dialog = new Dialog(); dialog.setDismissOnEscape(true); // close on esc (not working?) dialog.setDismissOnOutsideClick(true); // close when clicked outside dialog.setAutoCenter(true); dialog.setIsModal(true); dialog.setShowEdges(false); dialog.setBorder("1px solid #555555"); // show a line around the box dialog.setShowHeader(false); dialog.setShowToolbar(false); dialog.setAutoSize(true); dialog.setBackgroundColor("#FFFFFF"); // without this you could see true // the dialog in some browsers final DynamicForm dialogForm = new DynamicForm(); final TextItem textItem = new TextItem("input"); final ButtonItem btnItem = new ButtonItem("Ok"); btnItem.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { JavaScriptObject jsObject = JSOHelper.createObject(); Float value = new Float((String) textItem.getValue()); JSOHelper.setAttribute(jsObject, MyPercentageItem.FIELD_DOUBLE, value); MyPercentageEditor.setCurrentValue(jsObject); } }); btnItem.setColSpan(2); btnItem.setAlign(Alignment.RIGHT); btnItem.setWidth(100); dialogForm.setItems(textItem, btnItem); dialog.addItem(dialogForm); } // set the specified value and dismiss the picker dialog private static void setCurrentValue(Object value) { SC.logWarn("value before setValue is called: " + JSOHelper.getAttribute((JavaScriptObject) value, MyPercentageItem.FIELD_DOUBLE)); currentEditor.setValue(value); dialog.hide(); } // show the picker dialog at the specified position private static void showDialog(int left, int top) { dialog.show(); dialog.moveTo(left, top); } }
Comment