SmartClient Version: v8.3p_2013-02-20/LGPL Development Only (built 2013-02-20)
FF 17.0.3 ESR
GWT 2.5
Windows 7
Executed test in FF 17.0.3 ESR browser itself
---
I have an issue whereas the RelativeDateItem will not become enabled until the second attempt to enable. Sequence to reproduce using this code below:
1. Click Enable 1 (Notice change in relativedateitem's but they do not become completely enabled - only dropdown, not calendar picker).
2. Click Enable 2 (still not enabled)
3. Click Disable
4. Click Enable 1 (Both relativedateitem's become enabled as expected)
FF 17.0.3 ESR
GWT 2.5
Windows 7
Executed test in FF 17.0.3 ESR browser itself
---
I have an issue whereas the RelativeDateItem will not become enabled until the second attempt to enable. Sequence to reproduce using this code below:
1. Click Enable 1 (Notice change in relativedateitem's but they do not become completely enabled - only dropdown, not calendar picker).
2. Click Enable 2 (still not enabled)
3. Click Disable
4. Click Enable 1 (Both relativedateitem's become enabled as expected)
Code:
package com.corp.smartgwt.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.util.DateUtil;
import com.smartgwt.client.widgets.form.fields.RadioGroupItem;
import com.smartgwt.client.widgets.form.fields.RelativeDateItem;
import com.smartgwt.client.util.DateDisplayFormatter;
import com.smartgwt.client.util.DateParser;
import com.smartgwt.client.data.RelativeDate;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.TimeUnit;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
import com.smartgwt.client.widgets.form.validator.DateRangeValidator;
import java.util.Date;
public class SmartGwt implements EntryPoint {
private RelativeDateItem theStartDateItem;
private RelativeDateItem theEndDateItem;
private static String DATE_FORMAT = "dd.MMM.yyyy HH:mm";
private static String RADIOGROUP_NAME = "radiogroup1";
private RadioGroupItem theFilterRadioGroup;
private static final String RB1_LABEL_TEXT = "Disable";
private static final String RB2_LABEL_TEXT = "Enable 1";
private static final String RB3_LABEL_TEXT = "Enable 2";
@Override
public void onModuleLoad() {
HLayout layout = new HLayout();
DynamicForm form = new DynamicForm();
getStartDateItem().disable();
getEndDateItem().disable();
form.setFields(getFilterRadioGroup(), getStartDateItem(), getEndDateItem());
layout.addMember(form);
layout.draw();
}
/**
* This method returns a RadioGroupItem consisting of None,
* Image Date, and Load Date. It uses lazy initialization.
* @return RadioGroupItem
*/
private RadioGroupItem getFilterRadioGroup()
{
if (theFilterRadioGroup == null)
{
theFilterRadioGroup = new RadioGroupItem(RADIOGROUP_NAME);
theFilterRadioGroup.setValueMap(RB1_LABEL_TEXT,
RB2_LABEL_TEXT,
RB3_LABEL_TEXT);
theFilterRadioGroup.setShowTitle(false);
theFilterRadioGroup.setDefaultValue(RB1_LABEL_TEXT);
theFilterRadioGroup.setGlobalTabIndex(21);
theFilterRadioGroup.addChangedHandler(new ChangedHandler()
{
/*
* This method should fire anytime a user changes the radio button selection.
*/
@Override
public void onChanged(ChangedEvent event)
{
if (theFilterRadioGroup.getValueAsString().equals(RB1_LABEL_TEXT))
{
getStartDateItem().disable();
getEndDateItem().disable();
}
else if (theFilterRadioGroup.getValueAsString().equals(RB2_LABEL_TEXT))
{
getStartDateItem().enable();
getEndDateItem().enable();
}
else
{
getStartDateItem().enable();
getEndDateItem().enable();
}
}
});
}
return theFilterRadioGroup;
}
private void changeDateFormat()
{
DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter()
{
public String format(Date date)
{
if(date == null)
{
return null;
}
else
{
final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
return dateFormatter.format(date);
}
}
});
// It is a requirement that we implement a custom date parser or the onChanged event
// will not fire.
DateUtil.setDateParser(new DateParser()
{
public Date parse(String dateString)
{
final DateTimeFormat format = DateTimeFormat.getFormat(DATE_FORMAT);
return format.parse(dateString);
}
});
}
private RelativeDateItem getStartDateItem()
{
if (theStartDateItem == null)
{
changeDateFormat();
theStartDateItem = new RelativeDateItem("start_date");
theStartDateItem.setTitle("Start");
theStartDateItem.setShowFutureOptions(false);
theStartDateItem.setShowPastOptions(true);
// This DateRangeValidator will prevent us from setting the startDate in the future
// past Today
DateRangeValidator startValidator = new DateRangeValidator();
startValidator.setMax(new Date());
theStartDateItem.setValidators(startValidator);
theStartDateItem.setValidateOnChange(true);
// By setting this to essentially a blank LinkedHashMap, it will clear out the preset
// options we do not want.
// theStartDateItem.setPresetOptions(new LinkedHashMap());
theStartDateItem.setTimeUnitOptions(getTimeOptions());
theStartDateItem.setDefaultQuantity(1);
theStartDateItem.setOverflow(Overflow.VISIBLE);
theStartDateItem.addChangedHandler(new ChangedHandler()
{
@Override
public void onChanged(ChangedEvent event)
{
// Test if this is a relative date selection so we can save it that way
RelativeDate relDate = theStartDateItem.getRelativeDate();
Date startDate = (Date)theStartDateItem.getValue();
Date endDate = (Date)getEndDateItem().getValue();
// Per the JavaDoc, compareTo returns less than 0 if the date is before the compared
// date. So in this case, if the endDate is before the startDate, then we show
// the error. No changes will be made to the model until the error is cleared.
if (endDate.compareTo(startDate) < 0)
{
getEndDateItem().getForm()
.setFieldErrors("end_date", "invalid date", true);
}
else
{
getEndDateItem().getForm()
.clearFieldErrors("end_date", true);
}
}
});
}
return theStartDateItem;
}
/**
* This will return an array of SmartGWT TimeUnit options that we want to add to our drop-down
* for the Start and End date RelativeDateItem's
*
* @return array of TimeUnit's
*/
private TimeUnit[] getTimeOptions()
{
TimeUnit[] units = new TimeUnit[5];
units[0] = TimeUnit.HOUR;
units[1] = TimeUnit.DAY;
units[2] = TimeUnit.WEEK;
units[3] = TimeUnit.MONTH;
units[4] = TimeUnit.YEAR;
return units;
}
/**
* This will initialize and construct the end RelativeDateItem
* @return Ending RelativeDateItem
*/
private RelativeDateItem getEndDateItem()
{
if (theEndDateItem == null)
{
changeDateFormat();
theEndDateItem = new RelativeDateItem("end_date");
theEndDateItem.setTitle("End:");
// By setting this to essentially a blank LinkedHashMap, it will clear out the preset
// options we do not want.
// theEndDateItem.setPresetOptions(new LinkedHashMap());
theEndDateItem.setOverflow(Overflow.VISIBLE);
theEndDateItem.setShowFutureOptions(false);
theEndDateItem.setShowPastOptions(true);
theEndDateItem.setTimeUnitOptions(getTimeOptions());
theEndDateItem.setDefaultQuantity(1);
theEndDateItem.addChangedHandler(new ChangedHandler()
{
@Override
public void onChanged(ChangedEvent event)
{
// Test if this is a relative date selection so we can save it that way
RelativeDate relDate = theEndDateItem.getRelativeDate();
Date startDate = (Date)getStartDateItem().getValue();
Date endDate = (Date)theEndDateItem.getValue();
// Per the JavaDoc, compareTo returns less than 0 if the date is before the compared
// date. So in this case, if the endDate is before the startDate, then we show
// the error.
if (endDate.compareTo(startDate) < 0)
{
theEndDateItem.getForm()
.setFieldErrors("end_date", "invalid date", true);
}
else
{
// Clear any errors on the field and save the changes to the model
theEndDateItem.getForm()
.clearFieldErrors("end_date", true);
}
}
});
}
return theEndDateItem;
}
}
Comment