Announcement

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

    Validator does not work when it is applied in Editor Customizer

    Hi Isomorphic,

    please take a look at this one.
    If I use the same validator for ListGridField then it works as expected (dietLGF.setValidators(validator);).
    Is this a bug or I'm doing something wrong?

    Using 12.0p/v12.0p_2018-09-18
    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.Version;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.Criterion;
    import com.smartgwt.client.types.OperatorId;
    import com.smartgwt.client.types.ValidatorType;
    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.Validator;
    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 extends VLayout implements EntryPoint {
        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();
                }
            });
    
            setWidth100();
            setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    new MyWindow().show();
                }
            });
            addMember(recreateBtn);
            new MyWindow().show();
            draw();
        }
    
        private class MyWindow extends Window {
    
            public MyWindow() {
                setWidth(800);
                setHeight(600);
                setMembersMargin(0);
                setModalMaskOpacity(70);
                setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                SC.logWarn(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                setShowMinimizeButton(false);
                setIsModal(true);
                setShowModalMask(true);
                centerInPage();
    
                ListGrid mainLG = new MainLG();
    
                addItem(mainLG);
            }
    
            private class MainLG extends ListGrid {
                public MainLG() {
                    setDataSource("animals");
    
                    setEditorCustomizer(new ListGridEditorCustomizer() {
                        @Override
                        public FormItem getEditor(ListGridEditorContext context) {
                            if (context.getEditedRecord().getAttributeAsString("commonName").startsWith("Elephant")) {
                                if ("diet".equals(context.getEditField().getName())) {
                                    TextItem ti = new TextItem("diet");
                                    Validator validator = new Validator();
                                    validator.setType(ValidatorType.ISINTEGER);
                                    ti.setValidators(validator);
                                    ti.setValidateOnChange(true);
                                    return ti;
                                }
                            }
                            return null;
                        }
                    });
    
                    ListGridField commonNameLGF = new ListGridField("commonName");
                    ListGridField dietLGF = new ListGridField("diet");
                    dietLGF.setCanEdit(true);
    
                    setFields(commonNameLGF, dietLGF);
    
                    fetchData(new AdvancedCriteria(new Criterion("commonName", OperatorId.STARTS_WITH, "Elephant")));
                }
            }
        }
    }
    Best regards
    Pavo

    #2
    Hi Isomorphic,

    the same situation with "setCanEdit".

    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.Version;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.Criterion;
    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.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 extends VLayout implements EntryPoint {
        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();
                }
            });
    
            setWidth100();
            setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    new MyWindow().show();
                }
            });
            addMember(recreateBtn);
            new MyWindow().show();
            draw();
        }
    
        private class MyWindow extends Window {
    
            public MyWindow() {
                setWidth(800);
                setHeight(600);
                setMembersMargin(0);
                setModalMaskOpacity(70);
                setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                SC.logWarn(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                setShowMinimizeButton(false);
                setIsModal(true);
                setShowModalMask(true);
                centerInPage();
    
                ListGrid mainLG = new MainLG();
    
                addItem(mainLG);
            }
    
            private class MainLG extends ListGrid {
                public MainLG() {
                    setDataSource("animals");
    
                    setEditorCustomizer(new ListGridEditorCustomizer() {
                        @Override
                        public FormItem getEditor(ListGridEditorContext context) {
                            if (context.getEditedRecord().getAttributeAsString("commonName").startsWith("Elephant")) {
                                if ("diet".equals(context.getEditField().getName())) {
                                    TextItem ti = new TextItem("diet");
                                    ti.setCanEdit(false);
                                    return ti;
                                }
                            }
                            return null;
                        }
                    });
    
                    ListGridField commonNameLGF = new ListGridField("commonName");
                    ListGridField dietLGF = new ListGridField("diet");
                    dietLGF.setCanEdit(true);
    
                    setFields(commonNameLGF, dietLGF);
    
                    fetchData(new AdvancedCriteria(new Criterion("commonName", OperatorId.STARTS_WITH, "Elephant")));
                }
            }
        }
    }
    Best regards
    Pavo

    Comment


      #3
      We see the behavior you describe. Is there a reason why you don't want to just set the property on the ListGridField itself? With a ListGrid, the edit items are created from the ListGridFields so typically setting the property on the field itself is the most straightforward way to do it. The customizer you're using is, in general, intended for customizing things that can't be set directly on the field.

      Comment


        #4
        Yes, because the value of the second ListGridField depends on the value of the first ListGridField.
        E.g. two ListGridFields with folowing properties


        Click image for larger version

Name:	table.PNG
Views:	65
Size:	3.9 KB
ID:	255274


        For ListGridField with title "Default value" I have to apply validator(ISINTEGER) only for the first row, and not for second.
        Both fields are editable and user can change it.
        Last edited by pavo123; 26 Sep 2018, 23:29.

        Comment


          #5
          We've enhanced our logic in SGWT/SC 12.0p and newer branches to pick up validators and canEdit settings from the edit item, if any. This should be in the nightly builds dated 2018-09-29 and beyond.

          Comment


            #6
            It's working, thank you! This definitely helps a lot.

            Comment


              #7
              Hi Isomorphic,

              does this also affect TextItem.setMask() in 12.0p? I know I'll have a use for this one there after the switch.

              Thank you & Best regards
              Blama

              Comment


                #8
                We don’t see how that API would be related to this fix. Did you possibly mean to post this question in another thread?

                Comment

                Working...
                X