Hybrid View

  1. #1
    Ext User
    Join Date
    Jan 2009
    Posts
    14
    Vote Rating
    0
    Arthur B is on a distinguished road

      0  

    Default 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.

  2. #2
    Ext User
    Join Date
    Oct 2008
    Location
    Atlanta ,GA
    Posts
    239
    Vote Rating
    0
    kolli is on a distinguished road

      0  

    Default


    can you post some sample code so that we can have a look at it?

  3. #3
    Ext User
    Join Date
    Jan 2009
    Posts
    14
    Vote Rating
    0
    Arthur B is on a distinguished road

      0  

    Default


    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;
    }

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    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.

  5. #5
    Ext User
    Join Date
    Jan 2009
    Posts
    14
    Vote Rating
    0
    Arthur B is on a distinguished road

      0  

    Default


    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.

  6. #6
    Sencha User
    Join Date
    Oct 2011
    Posts
    6
    Vote Rating
    0
    lalous2012 is on a distinguished road

      0  

    Default 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.

Thread Participants: 3