From e9d2a4e233656cd634ae24c7e7c92483df30b671 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Wed, 6 Oct 2010 11:41:05 +0000 Subject: [PATCH] SWF-1271 Automatically add a constraints property to a dijit.form.DateTimeBox with the date pattern to use --- .../META-INF/web-resources/spring/Spring-Dojo.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spring-js-resources/src/main/resources/META-INF/web-resources/spring/Spring-Dojo.js b/spring-js-resources/src/main/resources/META-INF/web-resources/spring/Spring-Dojo.js index 6cdda3f6..fd47232a 100644 --- a/spring-js-resources/src/main/resources/META-INF/web-resources/spring/Spring-Dojo.js +++ b/spring-js-resources/src/main/resources/META-INF/web-resources/spring/Spring-Dojo.js @@ -44,16 +44,32 @@ dojo.declare("Spring.ElementDecoration", [Spring.AbstractElementDecoration, Spri console.error("Could not apply " + this.widgetType + " decoration. Element with id '" + this.elementId + "' not found in the DOM."); } else { + /* + * dijit.form.DateTextBox uses locale information when displaying a date and a + * fixed date format when parsing or serializing date values coming from the + * server-side. There is no way configure it to use a single date pattern, + * which is the reason for the code below. + */ var datePattern = this.widgetAttrs['datePattern']; if (datePattern && this.widgetType == 'dijit.form.DateTextBox') { if (!this.widgetAttrs['value']) { + // Help dijit.form.DateTextBox parse the server side date value. this.widgetAttrs['value'] = dojo.date.locale.parse(this.element.value, {selector : "date", datePattern : datePattern}); } if (!this.widgetAttrs['serialize']) { + // Help dijit.form.DateTextBox format the date to send to the server side. this.widgetAttrs['serialize'] = function(d, options){ return dojo.date.locale.format(d, {selector : "date", datePattern : datePattern}); } } + // Add a constraint that specifies the date pattern to use when displaying a date + // but don't interfere with any constraints that may have been specified. + if (!this.widgetAttrs['constraints']) { + this.widgetAttrs['constraints'] = {}; + } + if (!this.widgetAttrs['constraints'].datePattern) { + this.widgetAttrs['constraints'].datePattern = datePattern; + } } for (var copyField in this.copyFields) { copyField = this.copyFields[copyField];