Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid cell errors are cleared when tabbing to next row

    HI Isomorphic ,

    I am using a ListGridEditorCustomizer to customize the cell editor for a field similar to here.

    If an invalid value is entered in the cell editor, the cell displays an an error as expected; however, the cell error is cleared when tabbing to the next row.

    I have put together the following simple test case to illustrate this issue.

    Code:
     public void onModuleLoad() {
            final ListGrid grid = new ListGrid();
            grid.setWidth(400);
            grid.setHeight(300);
            grid.setCanEdit(Boolean.TRUE);
            grid.setEditEvent(ListGridEditEvent.CLICK);
            grid.setEditByCell(Boolean.TRUE);
            grid.setAutoSaveEdits(false);
    
            ListGridField nameField = new ListGridField("name", "Name");
            nameField.setWidth("*");
            nameField.setCanEdit(false);
            ListGridField valueField = new ListGridField("value", "Value Field", 170);
            ListGridField clearField = new ListGridField("clear", "Clear Field");
            clearField.setType(ListGridFieldType.BOOLEAN);
            clearField.setAlign(Alignment.CENTER);
    
            grid.setFields(nameField, valueField, clearField);
    
            grid.setData(getData());
            grid.setEditorCustomizer(context -> {
                ListGridField field = context.getEditField();
                if (field.getName().equals("value")) {
                    return new IntegerItem();
                }
                return context.getDefaultProperties();
            });
    
            grid.draw();
        }
    
        private ListGridRecord[] getData() {
            return new ListGridRecord[] { new NameValueRecord(1, "Item 1", 5), new NameValueRecord(2, "Item 2", 10),
                    new NameValueRecord(3, "Item 3", 15) };
        }
    
        public static class NameValueRecord extends ListGridRecord {
    
            public NameValueRecord(int id, String name, Object value) {
                setID(id);
                setName(name);
                setValue(value);
            }
    
            public void setID(int id) {
                setAttribute("ID", id);
            }
    
            public int getID() {
                return getAttributeAsInt("ID");
            }
    
            public void setValue(Object value) {
                setAttribute("value", value);
            }
    
            public Object getValue() {
                return getAttributeAsObject("value");
            }
    
            public void setName(String name) {
                setAttribute("name", name);
            }
    
            public String getName() {
                return getAttribute("name");
            }
        }
    After entering an invalid integer value for Item 2, the cell error is displayed as expected.

    Click image for larger version

Name:	cell_error.JPG
Views:	147
Size:	4.9 KB
ID:	267461

    However, after tabbing to Item 3, the cell error is cleared.
    Click image for larger version

Name:	cell_error_cleared.JPG
Views:	104
Size:	5.5 KB
ID:	267462

    If I remove the Clear Field, the cell errors are preserved so I'm not sure if this is a defect or just a limitation of the ListGridEditorCustomizer when the ListGrid has more than one editable field.

    SmartClient Version: v12.1p_2022-01-20/Pro Deployment (built 2022-01-20)

    Thanks.






    #2
    You need a type declaration on the field. What’s happening is that, since you declared an IntegerItem, validation is active while editing is active. Then, on row exit, validation happens without the editor, and there’s no type, so validation passes.

    This is intended, as it allows a field that is untyped, but has validated editing in certain contexts.

    Comment


      #3
      The test code I provided just uses an IntegerItem for simplicity, however, I will need to use different editors depending on the record. Is it possible to have the field type set dynamically based on a record attribute similar to the ListGridEditorCustomizer?

      Comment


        #4
        Interesting idea, but no, the way to make a polymorphic field currently is to install a validator that has logic to allow multiple different types, according to whatever your rules are.

        So, that’s going to require a DataSource definition in order to have somewhere to put the validator, but the DataSource need not be functional in terms of providing data - you can still just use setData() in the grid, and the DataSource basically acts as a “schema” that describes the records.

        Comment


          #5
          OK, I'll explore that approach. Thanks.

          Comment

          Working...
          X