Announcement

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

    How to get data out of DateRangeItem?

    I really like the look and functionality of the DateRangeItem, but I am having a lot of trouble getting any data out of it. DateRangeItem.getValue() returns a non null DateRange when either of the dates are set, but calling DateRange.getStartDate() or DateRange.getEndDate() or the relative versions of those always causes an exception.

    So I looked in the showcase and the only place I found using DateRangeItem is for filtering ListGrids. Those examples obviously work fine, but they use DateRangeItem.getCriterion() and I can't figure out how to actually get the dates out of the Criteria object. What type of object are the criteria stored as? When I call DateRangeItem.getCriterion().getAttribute("criteria").toString() it prints out as "[object Object],[object Object]". Trying to convert this to a Map or List both cause exceptions.

    #2
    Use SC.echo() for a JSON dump of what the criteria object contains. Like other Criteria/AdvancedCriteria objects, it's ready to be used with a variety of components, or modified.

    See also RelativeDateItem - possibly you don't want the pre-packaged range control but instead it's constituent parts.

    Comment


      #3
      How do I get values out of DateRangeItem, looking for an example? Help!!

      Comment


        #4
        I have the same issue with the DateRangeItem. I got the latest Pro on 10/1/2010. However I can only get the default value. The onchange event does not seem to be firing or setting the actual DateRange value.

        Thanks,

        Comment


          #5
          Hi All,
          To get the DateRange back you have to call getValue() directly on the DateRangeItem instance. Currently event.getValue() on a changed handler or form.getValue("fieldName") returns the underlying JavaScriptObject that represents the DateRange value.

          We'll be improving the values handling in this area in the near future but in the meantime here's some sample code demonstrating calling 'getValue()' on the item directly:

          Code:
          		DynamicForm testForm = new DynamicForm();
          		testForm.setID("tester");
          		DateRangeItem rangeItem = new DateRangeItem("foo");
          		rangeItem.addChangedHandler(new ChangedHandler() {
          			
          			@Override
          			public void onChanged(ChangedEvent event) {
          				DateRangeItem item = (DateRangeItem) event.getItem();
          				DateRange value = item.getValue();
          				if (value != null) {
          					SC.logWarn("changed firing = start:" + value.getStartDate() + ", end:" + value.getEndDate());
          				}
          				
          			}
          		});
          		
          		ButtonItem valsButton = new ButtonItem("foo", "Vals?");
          		valsButton.addClickHandler(new ClickHandler() {
          			
          			@Override
          			public void onClick(ClickEvent event) {
          				DateRangeItem item = (DateRangeItem)event.getForm().getItem("foo");
          				
          				DateRange value = item.getValue();
          				if (value == null) SC.say("unset");
          				SC.say("start:" + value.getStartDate() + ", end:" + value.getEndDate());
          				
          			}
          		});
          		
          		testForm.setItems(rangeItem, valsButton);
          		testForm.draw();

          Comment


            #6
            This has been resolved. Pick up the latest nightly.

            Comment

            Working...
            X