Announcement

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

    Date and Time chooser?

    Does smartGWT have a date and time chooser? I have DateChooser which only allows for date input and doesn't seem to have a popup mode.

    Ideally I am looking for a tool that will allow date and time to to be in a field, but will popup a selector for the user to choose a date and time from.

    Does this funcationality exist?

    #2
    Covered many times - use a DateItem and TimeItem in tandem. Search the forums for further advice.

    Comment


      #3
      Originally posted by Isomorphic
      Covered many times - use a DateItem and TimeItem in tandem. Search the forums for further advice.
      Thank you!

      Comment


        #4
        Just for the record, this is how to do it:

        Code:
                final DynamicForm scheduleForm = new DynamicForm();
                DateItem sendDate  = new DateItem();
                TimeItem sendTime = new TimeItem();
                
                scheduleForm.setFields(sendDate,sendTime);
                myPanel.addMember(scheduleForm);

        Comment


          #5
          In my solution above, the use of the TimeItem resulted in a very unsatisfactory user experience as it's just a text entry field. What you really want is to implement a spinner of for the hours and one for the minutes. Also, you really want this to default to now.

          Right now, there doesn't seem to be a way of getting the current time client-side. In Java, you do this using Calendar, but this isn't support in GWT at the Calendar class doesn't come with source to be compiled.

          So you are left with the very unsatisfactory result of having to use the deprecated Date.getHours() and Date.getMinutes() methods. If anyone knows a better way to do this that doesn't involve deprecated Java, please post here!

          Here is the solution that has a date picker, an hour spinner and a minute spinner with defaults to current date and time:
          Code:
                  final DynamicForm scheduleForm = new DynamicForm();
                  DateItem sendDate  = new DateItem();
                  sendDate.setDisplayFormat(DateDisplayFormat.TOSERIALIZEABLEDATE);
                  sendDate.setEnforceDate(true);
                  sendDate.setRequired(true);
                  sendDate.setInputFormat("YMD");
                  sendDate.setTitle("Send at:");
          
                  // This part sets up the spinners for choosing a time to send at
                  // We need to default it to now
                  
                  Date rightNow= new Date();
                  int hour= rightNow.getHours();
                  int min=rightNow.getMinutes();
          
                  SpinnerItem sendTimeHr = new SpinnerItem();
                  sendTimeHr.setName("sendTimeHr");
                  sendTimeHr.setMax(23);
                  sendTimeHr.setMin(0);
                  sendTimeHr.setTitle("Time:");
                  sendTimeHr.setWidth(2);
                  sendTimeHr.setDefaultValue(hour);
          
                  SpinnerItem sendTimeMin = new SpinnerItem();
                  sendTimeMin.setName("sendTimeMins");
                  sendTimeMin.setMax(59);
                  sendTimeMin.setMax(0);
                  sendTimeMin.setTitle(" ");
                  sendTimeMin.setDefaultValue(min);
                  
                  scheduleForm.setNumCols(6);
                  scheduleForm.setWidth(414);
                  scheduleForm.setBorder("2px solid black");
                  scheduleForm.setCellBorder(1);
                  scheduleForm.setFields(sendDate,sendTimeHr,sendTimeMin);
          Please note that I have the borders in for the form and cells so that it's clear how it's laid out. You want to remove those settings in the real world.

          Comment


            #6
            Hi, im using smartgwt 2.5.1 and i wanted to have spinner item for both hours and minutes as if i divide it then i have to handle combining of data etc. I tried it as this:
            Code:
            		final SpinnerItem from = new SpinnerItem(datetime);
            		from.setTitle("From");
            		from.setDefaultValue(new Date(1000 * 60 * 60 * 5));
            		from.setTimeFormatter(TimeDisplayFormat.TO24HOURTIME);
            		from.setDisplayFormat(TimeFormatter.TO24HOURTIME);
            		from.setEditorValueParser(new FormItemValueParser() {
            			@Override
            			public Object parseValue(String s, DynamicForm dynamicForm, FormItem formItem) {
            				return DateTimeFormat.getFormat("HH:mm:ss").parse(s);
            			}
            		});
            		from.setEditorValueFormatter(new FormItemValueFormatter() {
            			@Override
            			public String formatValue(Object o, Record record, DynamicForm dynamicForm, FormItem formItem) {
            				return DateTimeFormat.getFormat("HH:mm:ss").format((Date) o);
            			}
            		});
            		from.setValueFormatter(new FormItemValueFormatter() {
            			@Override
            			public String formatValue(Object o, Record record, DynamicForm dynamicForm, FormItem formItem) {
            				return DateTimeFormat.getFormat("HH:mm:ss").format((Date) o);
            			}
            		});
            This shows the date nicely(maybe except a timezone adjustment) but once i click the spinner it fails as the spinner tries to set the value to 0 and therefore date parsing fails. How can i achieve this? Is there another item that suits my needs better? If not how can i get this working?

            Thanks in advance!

            Comment

            Working...
            X