click-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrey Rybin (JIRA)" <j...@apache.org>
Subject [jira] Updated: (CLK-612) Better user experience with DateField (and CalendarField).
Date Mon, 18 Jan 2010 08:14:54 GMT

     [ https://issues.apache.org/jira/browse/CLK-612?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Andrey Rybin updated CLK-612:
-----------------------------

    Description: 
Current DateField.validate() is too strict. 

My suggestion is:

Add two properties: 
1) String prop similarDelimiters:

its format:   [oldChar1][newChar1] [oldChar2][newChar2].... if odd then ignore last char.


2) boolean prop  lenientValidation //def false


3) Modify  setValue (not tested):

    public void setValue(String value) {
        if (value != null && value.length() > 0) {
           value = value.trim();

     if (similarDelimiters != null && similarDelimiters.length > 0) {
       for (int i=0; i<similarDelimiters.length-1; i+=2) {
         value = value.replace(similarDelimiters.charAt(i), similarDelimiters.charAt(i+1));
      }//f
     }//i

            try {
                Date parsedDate = getDateFormat().parse(value);

                // Cache date for subsequent retrievals
                date = new Date(parsedDate.getTime());

            } catch (ParseException pe) {
                date = null;
            }

        } else {
            date = null;
        }
        super.setValue(value);
    }//setValue

Because people in Russia use different characters  (ex:  /,-, .(dot)) as date delimiters,
not one.

So I will set similarDelimiters to "-/\\/./" and pattern to dd/MM/yyyy - and it will work.


4) Modify validate()
dateFormat.setLenient(lenientValidation); 

  was:
Current DateField.validate() is too strict. 

My suggestion is:

Add String property   similarDelimiters:

its format:   [oldChar1][newChar1] [oldChar2][newChar2]....

if odd then ignore last char.


Modify setValue (not tested):

    public void setValue(String value) {
        if (value != null && value.length() > 0) {
           value = value.trim();

     if (similarDelimiters != null && similarDelimiters.length > 0) {
       for (int i=0; i<similarDelimiters.length-1; i+=2) {
         value = value.replace(similarDelimiters.charAt(i), similarDelimiters.charAt(i+1));
      }//f
     }//i

            try {
                Date parsedDate = getDateFormat().parse(value);

                // Cache date for subsequent retrievals
                date = new Date(parsedDate.getTime());

            } catch (ParseException pe) {
                date = null;
            }

        } else {
            date = null;
        }
        super.setValue(value);
    }//setValue

Because many people around me use /,-,.(dot) as date delimiters, not only / for example.

So I will set similarDelimiters to "-/\\/./" and pattern to dd/MM/yyyy - and it will work.


+ lenientValidation 
lenient should have possibility to tune it too

> Better user experience with DateField (and CalendarField).
> ----------------------------------------------------------
>
>                 Key: CLK-612
>                 URL: https://issues.apache.org/jira/browse/CLK-612
>             Project: Click
>          Issue Type: Improvement
>    Affects Versions: 2.1.0, 2.1.0 RC1
>            Reporter: Andrey Rybin
>
> Current DateField.validate() is too strict. 
> My suggestion is:
> Add two properties: 
> 1) String prop similarDelimiters:
> its format:   [oldChar1][newChar1] [oldChar2][newChar2].... if odd then ignore last char.
> 2) boolean prop  lenientValidation //def false
> 3) Modify  setValue (not tested):
>     public void setValue(String value) {
>         if (value != null && value.length() > 0) {
>            value = value.trim();
>      if (similarDelimiters != null && similarDelimiters.length > 0) {
>        for (int i=0; i<similarDelimiters.length-1; i+=2) {
>          value = value.replace(similarDelimiters.charAt(i), similarDelimiters.charAt(i+1));
>       }//f
>      }//i
>             try {
>                 Date parsedDate = getDateFormat().parse(value);
>                 // Cache date for subsequent retrievals
>                 date = new Date(parsedDate.getTime());
>             } catch (ParseException pe) {
>                 date = null;
>             }
>         } else {
>             date = null;
>         }
>         super.setValue(value);
>     }//setValue
> Because people in Russia use different characters  (ex:  /,-, .(dot)) as date delimiters,
not one.
> So I will set similarDelimiters to "-/\\/./" and pattern to dd/MM/yyyy - and it will
work.
> 4) Modify validate()
> dateFormat.setLenient(lenientValidation); 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message