Announcement

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

    ListGrid date editor causes format error

    Setting custom input format for date editor causes parse error.
    Version: 6.0p/LGPL/2016-10-23

    Code:
      public static final int RECORD_COUNT = 5;
      String customFormat = "yyyy.MM.dd";
    
      public void onModuleLoad()
      {
        ListGrid grid = new ListGrid();
        grid.setDataSource(new TestDS());
        grid.setAutoFetchData(true);
        grid.setWidth(600);
        grid.setHeight(400);
        grid.setEditByCell(true);
    
        grid.setCanEdit(true);
    
        RootPanel.get("listGridContainer").add(grid);
      }
    
      private class TestDS extends DataSource
      {
    
        public TestDS()
        {
          setID("localTestDS");
    
          DataSourceIntegerField dsField1 = new DataSourceIntegerField("F1", "Id");
          dsField1.setPrimaryKey(true);
    
          DataSourceDateField dsField2 = new DataSourceDateField("F2", "Field 2");
          dsField2.setFormat(customFormat);
          DateItem editorProperties = new DateItem();
          editorProperties.setFormat(customFormat);
          editorProperties.setInputFormat(customFormat);
          dsField2.setEditorProperties(editorProperties);
    
          setFields(dsField1, dsField2);
    
          setTestData(getData());
          setClientOnly(true);
        }
    
        private ListGridRecord[] getData()
        {
          ListGridRecord[] listGridRecords = new ListGridRecord[RECORD_COUNT];
          for (int i = 0; i < RECORD_COUNT; i++)
          {
            listGridRecords[i] = createRecord(i);
          }
          return listGridRecords;
        }
    
        private ListGridRecord createRecord(int i)
        {
          ListGridRecord listGridRecord = new ListGridRecord();
          listGridRecord.setAttribute("F1", i);
          listGridRecord.setAttribute("F2", new Date());
          return listGridRecord;
        }
      }
    Last edited by marchew; 24 Oct 2016, 08:08.

    #2
    See docs for setInputFormat(), you are not passing the expected parameter, which is a 3 character string to specify the order of inputs.

    Comment


      #3
      i changed this line to:
      Code:
       
       editorProperties.setInputFormat("YMD");
       editorProperties.setMaskDateSeparator(".");
      still doesn't work :(

      Comment


        #4
        If you set the input format to YMD and type in 10/20/2016, then that should be a parse error, you aren't following the format.

        Comment


          #5
          It wasn't typed. It was picked from editor's date picker. That's the clue.

          Comment


            #6
            We don't see this behavior - your original sample code works for us, once we correct it to call setInputFormat("YMD') on the editorProperties - that call and setFormat(customFormat) are the only required settings - your call to setDateMaskSeparator() is ineffective, since you aren't showing the mask anyway.

            Try clearing your caches, etc - if you still see an issue, show us your updated code and describe steps to reproduce, since we aren't reproducing it otherwise.

            Note that the typical way to customize date formatting is to do so system-wide, rather than by field, via DateUtil APIs.
            Last edited by Isomorphic; 27 Oct 2016, 22:34.

            Comment


              #7
              I just tried with 6.1-d20161027-SNAPSHOT and it works fine (thanks a lot!) but i was trying to achieve this in production build (6.0-p20161023).
              I think it doesn't matter anymore but for the record:

              My goal was to operate on one specific column (not system-wide) with date format: "yyyy.MM.dd"

              Code:
                public static final int RECORD_COUNT = 5;
                String customFormat = "yyyy.MM.dd";
              
                public void onModuleLoad()
                {
                  ListGrid grid = new ListGrid();
                  grid.setDataSource(new TestDS());
                  grid.setAutoFetchData(true);
                  grid.setWidth(200);
                  grid.setHeight(200);
                  grid.setEditByCell(true);
                  grid.setCanEdit(true);
              
                  RootPanel.get("listGridContainer").add(grid);
                }
              
                private class TestDS extends DataSource
                {
              
                  public TestDS()
                  {
                    setID("localTestDS");
              
                    DataSourceIntegerField dsField1 = new DataSourceIntegerField("F1", "Id");
                    dsField1.setPrimaryKey(true);
              
                    DataSourceDateField dsField2 = new DataSourceDateField("F2", "Field 2");
                    dsField2.setFormat(customFormat);
                    DateItem editorProperties = new DateItem();
                    editorProperties.setFormat(customFormat);
                    editorProperties.setInputFormat("YMD");
              //      editorProperties.setMaskDateSeparator(".");
                    dsField2.setEditorProperties(editorProperties);
              
                    setFields(dsField1, dsField2);
              
                    setTestData(getData());
                    setClientOnly(true);
                  }
              
                  private ListGridRecord[] getData()
                  {
                    ListGridRecord[] listGridRecords = new ListGridRecord[RECORD_COUNT];
                    for (int i = 0; i < RECORD_COUNT; i++)
                    {
                      listGridRecords[i] = createRecord(i);
                    }
                    return listGridRecords;
                  }
              
                  private ListGridRecord createRecord(int i)
                  {
                    ListGridRecord listGridRecord = new ListGridRecord();
                    listGridRecord.setAttribute("F1", i);
                    listGridRecord.setAttribute("F2", new Date());
                    return listGridRecord;
                  }
                }
              At the beginning ListGrid looks like this:
              Click image for larger version

Name:	Screenshot_4.png
Views:	77
Size:	4.4 KB
ID:	241063
              double click starts editor:
              Click image for larger version

Name:	Screenshot_5.png
Views:	53
Size:	5.3 KB
ID:	241064
              As you can see, format inside editor isn't quite right.
              After opening date picker:
              Click image for larger version

Name:	Screenshot_6.png
Views:	66
Size:	12.1 KB
ID:	241066
              I chose 26th...
              Click image for larger version

Name:	Screenshot_7.png
Views:	51
Size:	5.1 KB
ID:	241067
              Validation error occurs :(
              Attached Files

              Comment


                #8
                So i'm just waiting for production build. Thanks for help!

                Comment


                  #9
                  It's not clear if you're expecting further input from us here, but we're unable to reproduce what you show in your images, or find any other issues in this area.

                  Just setting your custom format on the DataSourceField enforces it throughout (for display, while editing, and after choosing a date from the picker) - however, edited values in your custom format will fail validation unless you also set inputFormat on the editorProperties.

                  Please retest with the latest build of your version from smartclient.com/builds.

                  Comment

                  Working...
                  X