Author: sascharodekamp Date: Tue Aug 7 05:51:10 2012 New Revision: 1370123
URL: http://svn.apache.org/viewvc?rev=1370123&view=rev Log: js issue causes error when invalid dates are entered (https://issues.apache.org/jira/browse/OFBIZ-4982). A patch from Christoph Neuroth: Reproduce: Enter "123" in a DateField. This will trigger a JS exception and the invalid value will be sent to the server on form submission, probably causing server-side exceptions in badly written backend code, resulting in really bad error messages for the user. Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=1370123&r1=1370122&r2=1370123&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original) +++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Tue Aug 7 05:51:10 2012 @@ -146,13 +146,17 @@ under the License. jQuery("#${id}_i18n").val(newValue); }); jQuery("#${id}_i18n").change(function() { - var dateFormat = Date.CultureInfo.formatPatterns.shortDate<#if shortDateInput?exists && !shortDateInput> + " " + Date.CultureInfo.formatPatterns.longTime</#if>; - var newValue = "" - if (this.value != "") { - var dateObj = Date.parseExact(this.value, dateFormat); - var ofbizTime = "<#if shortDateInput?exists && shortDateInput>yyyy-MM-dd<#else>yyyy-MM-dd HH:mm:ss</#if>"; + var dateFormat = Date.CultureInfo.formatPatterns.shortDate<#if shortDateInput?exists && !shortDateInput> + " " + Date.CultureInfo.formatPatterns.longTime</#if>, + newValue = "", + dateObj = Date.parseExact(this.value, dateFormat), + ofbizTime; + if (this.value != "" && dateObj !== null) { + ofbizTime = "<#if shortDateInput?exists && shortDateInput>yyyy-MM-dd<#else>yyyy-MM-dd HH:mm:ss</#if>"; newValue = dateObj.toString(ofbizTime); } + else { // invalid input + jQuery("#${id}_i18n").val(""); + } jQuery("#${id}").val(newValue); }); } else {

