Hi,
There is custom validator attached to DataSource field 'dateTo'. This validator depends on 'validFrom' field.
Edit enabled ListGrid uses this DataSource:
If you run this test case, enter grid's edit mode and change 'validTo' field value (the one validator is attached), then console shows this:
But if you run test case again and this time change 'validFrom' field value (dependent field), then console shows:
Value in condition() method is not set (null), so validator is not able to work properly in real application.
Thanks,
MichalG
SmartClient Version: v11.0p_2016-07-07/LGPL Development Only (built 2016-07-07)
FF 24.8.0 and Chrominium 38.0.2125.101
There is custom validator attached to DataSource field 'dateTo'. This validator depends on 'validFrom' field.
Edit enabled ListGrid uses this DataSource:
Code:
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.FieldType;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.events.DrawEvent;
import com.smartgwt.client.widgets.events.DrawHandler;
import com.smartgwt.client.widgets.form.validator.CustomValidator;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.VLayout;
import java.util.Date;
import java.util.HashMap;
public class MainEntryPoint implements EntryPoint {
public void onModuleLoad() {
layout();
}
private void layout() {
DataSource projectDS = new DataSource();
projectDS.setClientOnly(true);
DataSourceField idField = new DataSourceField();
idField.setType(FieldType.SEQUENCE);
idField.setName("id");
idField.setPrimaryKey(true);
idField.setHidden(true);
DataSourceTextField codeField = new DataSourceTextField();
codeField.setName("code");
DataSourceDateField validFromField = new DataSourceDateField();
validFromField.setName("validFrom");
DataSourceDateField validToField = new DataSourceDateField();
validToField.setName("validTo");
DateRangeFieldValidator dateRangeFieldValidator = new DateRangeFieldValidator();
dateRangeFieldValidator.setDependentFields(new String[] {"validFrom"});
validToField.setValidators(dateRangeFieldValidator);
projectDS.setFields(idField, codeField, validFromField, validToField);
final ListGrid lg = new ListGrid();
lg.setDataSource(projectDS);
lg.setCanEdit(true);
lg.setAutoSaveEdits(false);
lg.setWidth(300);
lg.addDrawHandler(new DrawHandler() {
public void onDraw(DrawEvent event) {
HashMap map = new HashMap();
map.put("id", "0");
map.put("validFrom", new Date());
map.put("validTo", new Date());
//lg.startEditingNew(map);
Record[] records = new Record[1] ;
records[0] = new Record(map);
lg.setData(records);
}
});
Button validateButton = new Button("Validate");
validateButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
lg.validateRow(0);
}
});
VLayout layout = new VLayout();
layout.addMember(lg);
layout.addMember(validateButton);
layout.draw();
}
public class DateRangeFieldValidator extends CustomValidator {
@Override
protected boolean condition(Object value) {
SC.logWarn("value=" + value);
SC.logWarn("record=" + getRecord());
return true;
}
}
}
Code:
14:06:17.422:MDN6:WARN:Log:value=Wed Jul 13 12:00:00 GMT+200 2016 14:06:17.423:MDN6:WARN:Log:record=com.smartgwt.client.data.Record@5 14:06:17.526:MUP5:WARN:Log:value=Wed Jul 13 12:00:00 GMT+200 2016 14:06:17.527:MUP5:WARN:Log:record=com.smartgwt.client.data.Record@6
Code:
14:43:23.937:MDN4:WARN:Log:value=null 14:43:23.938:MDN4:WARN:Log:record=com.smartgwt.client.data.Record@5 14:43:24.024:MUP2:WARN:Log:value=null 14:43:24.025:MUP2:WARN:Log:record=com.smartgwt.client.data.Record@6
Thanks,
MichalG
SmartClient Version: v11.0p_2016-07-07/LGPL Development Only (built 2016-07-07)
FF 24.8.0 and Chrominium 38.0.2125.101
Comment