Announcement

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

    Read-only validator applied in grid's filter editor

    In the following example I am using ValidatorType.READONLY with validateOnChange feature (real application case uses applyWhen criteria also).
    When user enters grid edit mode then "code" field is protected - nothing can be entered in it, as desired.
    However, when user enters filter for the same "code" field, then writing anything to filter data is also protected. This is NOT desired, as you already explained in this archive thread.
    Similar problem exists when such a DataSourceField with this kind of validator is bounded to FilterBuilder.
    Code:
    package pl.com.tech4.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.DOM;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.ValidatorType;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.events.DropMoveEvent;
    import com.smartgwt.client.widgets.events.DropMoveHandler;
    import com.smartgwt.client.widgets.form.validator.Validator;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    
    public class MainEntryPoint implements EntryPoint {
      
        public void onModuleLoad() {
    
            DOM.getElementById("loadingPicture").removeFromParent();
            layout();
            SC.showConsole();
        }
      
        private void layout() {
          
            DataSource ds = new DataSource();
            DataSourceField fieldId = new DataSourceField();
            fieldId.setName("id");
            fieldId.setPrimaryKey(true);
            fieldId.setHidden(true);
            DataSourceTextField fieldCode = new DataSourceTextField();
            fieldCode.setName("code");
            Validator validator = new Validator();
            validator.setType(ValidatorType.READONLY);
            validator.setValidateOnChange(true);
            fieldCode.setValidators(validator);
            ds.setFields(fieldId, fieldCode);
          
            ListGrid lg = new ListGrid();
            lg.setDataSource(ds);
            ListGridRecord[] records = new ListGridRecord[2];
            records[0] = new ListGridRecord();
            records[0].setAttribute("id", "1");
            records[0].setAttribute("code", "m/s");
            records[1] = new ListGridRecord();
            records[1].setAttribute("id", "2");
            records[1].setAttribute("code", "knots");
            lg.setData(records);
            lg.setCanEdit(true);
            lg.setShowFilterEditor(true);
          
            lg.draw();
        }
    }
    Thanks,
    MichalG

    SmartClient Version: v10.0p_2015-02-02/LGPL Development Only (built 2015-02-02)
    Firefox 24.8.0 (Gentoo linux)

    #2
    Hi Michael,
    For Filter-Editors (and search forms in general) we suppress validation by default. The validators, if specified at the DataSource field, or FormItem level, are actually still present in the search form or filter-editor, but are not typically run as part of the normal "filter" flow.
    However by setting "validateOnChange" to true, you are essentially overriding this and forcing validation to occur with every user edit, which is why you're running into this problem.

    Depending on your application design, a better solution for this might be to either use the simple DataSourceField canEdit property (which will disable editing for the field, but leave the filter editor unaffected), or possibly have a change handler specified on your field which returns false (rejecting the change) if certain circumstances are met.

    Regards
    Isomorphic Software

    Comment


      #3
      Thank you for this explanation.
      I am going to use change event to solve this issue, as you suggested.

      However, I would also opt for not to trigger validator even if it is marked as "validateOnChange". At least from our point of view, it does not make sense to validate when entering criteria regardless of "validateOnChange".

      Regards,
      MichalG

      Comment

      Working...
      X