Announcement

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

    Validation called automatically onChange for validation-error DateItems

    Hi Isomorphic,

    I noticed following error in my application (v11.1p_2018-05-07). If a DateItem with (server) validation error is changed, it auto-triggers DynamicForm validation on the server again. This should not happen IMHO (like it does not for TextItem).
    Please see this video:
    Click image for larger version

Name:	Validation called automatically.gif
Views:	266
Size:	243.5 KB
ID:	253415

    BuiltInDS.java:
    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.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.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.DateItem;
    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");
    
            DateItem di = new DateItem();
            di.setUseTextField(true);
            DateItem.setDefaultProperties(di);
    
            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(450);
                setHeight(600);
                setTitle("Validation called too often for DateItems (onChange) (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
                setShowMinimizeButton(false);
                setIsModal(true);
                setShowModalMask(true);
                centerInPage();
    
                final DynamicForm df = new DynamicForm();
                df.setDataSource(DataSource.get("supplyItem"));
                df.setInitialCriteria(new AdvancedCriteria(new Criterion("SKU", OperatorId.EQUALS, "58074602")));
                df.setAutoFetchData(true);
                addItem(df);
    
                IButton saveBtn = new IButton("Save data", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        df.saveData();
                    }
                });
                addItem(saveBtn);
    
                IButton validateBtn = new IButton("Validate data", new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        df.validate();
                    }
                });
                addItem(validateBtn);
            }
        }
    }
    supplyItem.ds.xml:
    Code:
    <DataSource ID="supplyItem" serverType="sql" tableName="supplyItem" titleField="itemName" testFileName="/examples/shared/ds/test_data/supplyItem.data.xml"
        dbImportFileName="/examples/shared/ds/test_data/supplyItemLarge.data.xml">
        <fields>
            <field name="itemID" type="sequence" hidden="true" primaryKey="true" />
            <field name="itemName" type="text" title="Item" length="128" required="true">
                <validators>
                    <validator type="serverCustom">
                        <serverCondition><![CDATA["$value" < "Z"]]></serverCondition>
                    </validator>
                </validators>
            </field>
            <field name="SKU" type="text" title="SKU" length="10" required="true" />
            <field name="description" type="text" title="Description" length="2000" />
            <field name="category" type="text" title="Category" length="128" required="true" foreignKey="supplyCategory.categoryName" />
            <field name="units" type="enum" title="Units" length="5">
                <valueMap>
                    <value>Roll</value>
                    <value>Ea</value>
                    <value>Pkt</value>
                    <value>Set</value>
                    <value>Tube</value>
                    <value>Pad</value>
                    <value>Ream</value>
                    <value>Tin</value>
                    <value>Bag</value>
                    <value>Ctn</value>
                    <value>Box</value>
                </valueMap>
            </field>
            <field name="unitCost" type="float" title="Unit Cost" required="true">
                <validators>
                    <validator type="floatRange" min="0" errorMessage="Please enter a valid (positive) cost" />
                    <validator type="floatPrecision" precision="2" errorMessage="The maximum allowed precision is 2" />
                </validators>
            </field>
            <field name="inStock" type="boolean" title="In Stock" />
            <field name="nextShipment" type="date" title="Next Shipment">
                <validators>
                    <validator type="serverCustom">
                        <serverObject lookupStyle="new" className="com.smartgwt.sample.server.listener.DateValidator" />
                    </validator>
                </validators>
            </field>
        </fields>
    </DataSource>
    Best regards
    Blama

    #2
    Sorry for the delay on getting you an answer but some review of the background of the code was in order. Anyway, a fix has been checked in and will be available in builds starting on 06/02/2018. Local validation is performed when selecting a date from the chooser and the current manually-entered date is invalid. No server validation request will be attempted. The thought is that since a manually-entered date could easily be mistyped and choosing a date from the picker is guaranteed to be a good date, errors relating to data entry should be cleared immediately. In your case it is still possible that upon save or manual validation the server validator(s) fails and the new error(s) is shown.

    Comment


      #3
      Hi Isomorphic,

      this is working as expected now.

      Thank you & Best regards
      Blama

      Comment

      Working...
      X