-
28 Jan 2009 7:45 AM #1
Allow Blank in Date Field
Allow Blank in Date Field
Does anyone know if it's possible to allow a blank entry in a date field? I have tried setting the setAllowBlank() to true, built a property editor, and a validator. Nothing seems to allow a blank field once you have entered a valid date into the field.
-
28 Jan 2009 7:49 AM #2
can you post some sample code so that we can have a look at it?
-
28 Jan 2009 8:03 AM #3
Code:/** * @return a date field with no label */ public DateField createDateField() { final DateField field = new DateField(); field.setHideLabel(true); field.addStyleName("dateField"); field.setWidth(200); field.setAllowBlank(true); field.setPropertyEditor(new DateTimePropertyEditor() { @Override public Date convertStringValue(String value) { if (value != null && !value.isEmpty()) { try { return DateTimeFormat.getFormat(DATE_FORMAT).parse(value); } catch (final IllegalArgumentException e) { return null; } } else return null; }@Override public DateTimeFormat getFormat() { return DateTimeFormat.getFormat(DATE_FORMAT); }@Override public String getStringValue(Date value) { if (value != null) return DateTimeFormat.getFormat(DATE_FORMAT).format(value); else return ""; } }); field.setValidator(new Validator<Date, DateField>() { public String validate(DateField field, String value) { if (value != null && !value.isEmpty()) { try { Date date = DateTimeFormat.getFormat(DATE_FORMAT).parse(value); if (date != null) return null; else return "Invalid Date Format"; } catch (final IllegalArgumentException e) { return "Invalid Date Format"; } } else return null; } }); return field;}
-
28 Jan 2009 2:38 PM #4
http://extjs.com/explorer/#forms
The DateField there is allowed to be blank. If i type something non valid in it it is marked invalid. If i clear the field it is vlaid again.
-
28 Jan 2009 2:44 PM #5
The property editor is probably what is preventing the date field from accepting an empty value. I got around my problem by adding a "clear date" icon button.
-
4 Dec 2012 1:23 AM #6
dateField issue
dateField issue
Hello,
I am using dateField with allowBlank = true because it is no mandatory to fill this field in the form. But when i click save I get an error : save Failed, sql error:PreparedStatementCallback; uncategorized SQLException for SQL [ INSERT INTO tableName (....) VALUES ( .....) ]; SQL state [null]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type.
Please any help ?
Thanks in advance.


Reply With Quote