Results 1 to 6 of 6

Thread: DateField - I want to make format like "01.02.16 23:59:59"

    You found a bug! We've classified it as EXTGWT-4584 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha Premium Member
    Join Date
    Mar 2015
    Posts
    10

    Question DateField - I want to make format like "01.02.16 23:59:59"

    Hello!

    I use GWT version 2.7.0, GXT version 3.1.4.

    I use DateField, want after selecting a date using DatePicker time was "23:59:59"

    code snippet:

    Code:
    private final DateField perEnd;
    
    ...
    
    
    perEnd.getDatePicker().addValueChangeHandler(new ValueChangeHandler<Date>() {
        @Override
    public void onValueChange(final ValueChangeEvent<Date> event) {
            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                @Override
    public void execute() {
                    Date victim = event.getValue();
                    if (victim != null){
                        victim.setHours(23);
                        victim.setMinutes(59);
                        victim.setSeconds(59);
                        perEnd.setValue(victim, true, true);
                        Info.display("debug", "fired, try set value " + victim +", now value " + perEnd.getCurrentValue());
                    }
                }
            });
        }
    });

    I'm doing something wrong - because the time is still "00:00:00"

    See attached file:

    screen.jpg


    I tried to rearrange the focus, using scheduleDeffered - unsuccessfully. Can you suggest how to make the time to be "23:59:59"?
    Last edited by kdtemnen; 15 Nov 2015 at 11:48 PM. Reason: gwt & gxt versions

  2. #2
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,165

    Default

    Instead of using field.getCurrentValue(), try field.getValue();. We've got a bug in for how the value is passed from the date picker to the date field. It passes it using the property editor and returns it as a string. Since you set the value, you can get the value.

    Code:
    import java.util.Date;
    
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.event.logical.shared.ValueChangeEvent;
    import com.google.gwt.event.logical.shared.ValueChangeHandler;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.sencha.gxt.widget.core.client.form.DateField;
    import com.sencha.gxt.widget.core.client.info.Info;
    
    
    public class DatePickerWithValueChangeEvent implements EntryPoint {
    
    
      @Override
      public void onModuleLoad() {
        final DateField field = new DateField();
        field.getDatePicker().addValueChangeHandler(new ValueChangeHandler<Date>() {
          @Override
          public void onValueChange(ValueChangeEvent<Date> event) {
            Date victim = event.getValue();
            if (victim != null) {
              victim.setHours(23);
              victim.setMinutes(59);
              victim.setSeconds(59);
              field.setValue(victim);
              String m = "1111111 fired, try set value " + victim + ", now value " + field.getValue();
              Info.display("debug", m);
              System.out.println(m);
            }
          }
        });
    
    
        RootPanel.get().add(field);
      }
    
    
    }
    Does that help?

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2015
    Posts
    10

    Default

    The debug message indicates the correct value, but the value in the input field has not changed.

    I need to change (redrawn) the value in the input field

    code:


    Code:
    private final DateField perBeg;
    private final DateField perEnd;
    ...
    
    perEnd.getDatePicker().addValueChangeHandler(new ValueChangeHandler<Date>() {
        @Override
    public void onValueChange(final ValueChangeEvent<Date> event) {
            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                @Override
    public void execute() {
                    Date victim = event.getValue();
                    if (victim != null){
                        victim.setHours(23);
                        victim.setMinutes(59);
                        victim.setSeconds(59);
                        perEnd.setValue(victim, true, true);
                        perBeg.focus();
                        Info.display("debug", "fired, try set value " + victim +", now value " + perEnd.getValue());
                    }
                }
            });
        }
    });
    Result:

    screen3.jpg

  4. #4
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,165

    Default

    Oh I made an incorrect assumption, now I see what's going on. I've reported the inconsistent state as a bug. Finish editing is called and clobbers the value once it's set. So to workaround that, I called it a bit earlier so the next value would be taken.

    Look for the tildas ~~~~ for the workaround.
    Code:
    import java.util.Date;
    
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.event.logical.shared.ValueChangeEvent;
    import com.google.gwt.event.logical.shared.ValueChangeHandler;
    import com.google.gwt.i18n.shared.DateTimeFormat;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.sencha.gxt.widget.core.client.form.DateField;
    import com.sencha.gxt.widget.core.client.form.DateTimePropertyEditor;
    import com.sencha.gxt.widget.core.client.info.Info;
    
    
    public class DatePickerWithValueChangeEvent implements EntryPoint {
    
    
      @Override
      public void onModuleLoad() {
        DateTimeFormat format = DateTimeFormat.getFormat("yyyy.MM.dd HH:mm:ss");
        DateTimePropertyEditor propertyEditor = new DateTimePropertyEditor(format);
        
        Date date = new Date();
        
        
        final DateField field = new DateField(propertyEditor);
        field.setValue(date);
        field.setWidth(200);
        
        field.getDatePicker().addValueChangeHandler(new ValueChangeHandler<Date>() {
          @Override
          public void onValueChange(final ValueChangeEvent<Date> event) {
            // ~~~~ workaround
            field.finishEditing();
            
            final Date victim = event.getValue();
            if (victim != null) {
              victim.setHours(23);
              victim.setMinutes(59);
              victim.setSeconds(59);
              field.setValue(victim);
              
              String m = "1111111 fired, try set value " + victim + ", now value " + field.getValue();
              Info.display("debug", m);
              System.out.println(m);
            }
          }
        });
    
    
        RootPanel.get().add(field);
      }
    
    
    }
    I've reported and link the bug. Would this help get you further along?

  5. #5
    Sencha Premium Member
    Join Date
    Mar 2015
    Posts
    10

    Default

    Workaround helped. Thank you very much for your help, the problem is solved!

  6. #6
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,165

    Default

    Good to hear. Thanks for the feedback.

Similar Threads

  1. Replies: 4
    Last Post: 27 Jan 2014, 3:04 AM
  2. datefield in format "m.Y"
    By PSB in forum Ext: Q&A
    Replies: 1
    Last Post: 31 Oct 2012, 4:20 AM
  3. Replies: 2
    Last Post: 3 Apr 2012, 8:15 AM
  4. [FIXED] Spaces in the "id" property make the "preview" non functional
    By boboka in forum Ext Designer: Bugs
    Replies: 1
    Last Post: 27 Oct 2011, 10:07 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •