Announcement

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

    ListGrid custom cell editor bug with validateOnChange

    Hi Isomorphic,

    please see this builtInDS-based testcase using 5.1d SNAPSHOT_v10.1d_2015-10-30. I found this while investigating for this report. As I don't use it in my application, this has no priority for me, but definitely is a bug.

    BuiltInDS.java:
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.Criterion;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.validator.RegExpValidator;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridEditorContext;
    import com.smartgwt.client.widgets.grid.ListGridEditorCustomizer;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS implements EntryPoint {
        private VLayout mainLayout;
        private IButton recreateBtn;
    
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            mainLayout = new VLayout(20);
            mainLayout.setWidth100();
            mainLayout.setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    recreate();
                }
            });
            mainLayout.addMember(recreateBtn);
            recreate();
            mainLayout.draw();
        }
    
        private void recreate() {
            Window w = new Window();
            w.setWidth("95%");
            w.setHeight("95%");
            w.setMembersMargin(0);
            w.setModalMaskOpacity(70);
            w.setTitle("FormItem \"eats\" 1st conflicting character.");
            w.setShowMinimizeButton(false);
            w.setIsModal(true);
            w.setShowModalMask(true);
            w.centerInPage();
            {
                final ListGrid testGrid = new ListGrid(DataSource.get("employees"));
                testGrid.setCanEdit(true);
    
                ListGridField nameLGF = new ListGridField("Name");
                nameLGF.setTitle("\"|\" separated list of numbers");
                testGrid.setFields(nameLGF);
    
                testGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
                    public FormItem getEditor(ListGridEditorContext context) {
                        ListGridField field = context.getEditField();
                        if (field.getName().equals("Name")) {
                            TextItem editNameTI = new TextItem("Name");
                            RegExpValidator aToMValidator = new RegExpValidator("^[0-9]+(\\|[0-9]+)*$");
                            editNameTI.setValidators(aToMValidator);
                            editNameTI.setValidateOnChange(true);
                            return editNameTI;
                        } else
                            return context.getDefaultProperties();
                    }
                });
    
                AdvancedCriteria ac = new AdvancedCriteria(new Criterion("EmployeeId", OperatorId.EQUALS, 4));
                testGrid.fetchData(ac);
                w.addItem(testGrid);
            }
            w.show();
        }
    }
    Steps to recreate:
    1. Start editing via double click
    2. Mark and remove text
    3. Enter 123 one after another. No error.
    4. Enter "a". "a" not printed, but validation error appears.
    5. Enter "1". Error disappears, "a" is printed.
    6. Keep entering "1". Only every 2nd "1" is printed, "a" appears and disappears, validation error appears and disappears,
    As I'm not using setValidateOnChange(), this has no priority for me.

    Best regards
    Blama

    EDIT:
    PS: I tried this in a DynamicForm instead of ListGrid-setEditorCustomizer before, which worked like expected.
    Last edited by Blama; 9 Nov 2015, 06:43.

    #2
    As with the other thread you reference, the problem is probably that you are applying your validation logic directly to the editor for the field (the generated FormItem), not to the ListGrid field itself.
    The right way to do this is typically to set the validators and the validateOnChange settings at the field level.

    If this doesn't get things working for you or isn't an option for some reason, please let us know.

    Regards
    Isomorphic Software

    Comment

    Working...
    X