I posted this in August 2006... but there were no replies. I am really trying to get handle how to effectively do date validation in Cocoon forms.
Step 1 is simply to see that the date is, in fact, a valid date. The obvious (to me, anyway) approach would be to have a simple: <fd:validation> <fd:date> <fd:failmessage>Not a valid date!</fd:failmessage> </fd:date> </fd:validation> But this does not exist, so... Merico Raffaele proposed an approach using javascript: http://marc.info/?l=xml-cocoon-users&m=113411711707855&w=2 <fd:validation> <fd:javascript> var enteredValue = cocoon.request.get(widget.getRequestParameterName()); var trimmedValue = enteredValue.replaceAll("\\s", ""); if (!isDate(trimmedValue, "yyyy.M.d")) { var valError = new org.apache.cocoon.forms.validation.ValidationError("invalidDate"); widget.setValidationError(valError); return false; } </fd:javascript> </fd:validation> Andreas Hartmann's approach was to use formatting: http://marc.info/?l=xml-cocoon-users&m=110674013328824&w=2 <fd:datatype base="date"> <fd:convertor type="formatting"> <fd:patterns> <fd:pattern>dd.MM.yyyy</fd:pattern> </fd:patterns> </fd:convertor> </fd:datatype> but found this lead to problems with values like 20.01.200x which is interpreted as 20.01.200 and results in the formatted value 20.01.0200 My "ideal" would be to specify the format for the user, such yyyy/MM/dd, and require them to enter ALL the values, following which the date could be validated: Step 1: for plausibility (is this a "real" date) and Step 2: for range, if needed (e.g. "after today", or "between 2006/11/20 and 2007/12/31) otherwise, if entries such as 4/5/6 are allowed (which seems to be the case with formatter above), then a huge amount of ambiguity is present. Is there, in fact, a definitive way of doing server side date validation - preferably one that does not involve lots of customisation - and can someone clearly lay out how to do it?? Much appreciated, Derek -- This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html. This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.
