From 26f5f2e504c0b582f1b86dad1fdfed2c720c9a4f Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 30 Mar 2012 14:30:26 +0000 Subject: [PATCH] Stop error on invalid format, use a default --- etemplate/js/et2_widget_date.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/etemplate/js/et2_widget_date.js b/etemplate/js/et2_widget_date.js index ba8ac9d2e3..d6e9eecf0a 100644 --- a/etemplate/js/et2_widget_date.js +++ b/etemplate/js/et2_widget_date.js @@ -234,6 +234,13 @@ var et2_date_duration = et2_date.extend({ this.options.display_format = this.options.display_format.replace("%",""); } + // Clean formats + this.options.display_format = this.options.display_format.replace(/[^dhm]/,''); + if(!this.options.display_format) + { + this.options.display_format = this.attributes.display_format["default"]; + } + // Get translations this.time_formats = { "d": this.options.short_labels ? this.egw().lang("m") : this.egw().lang("Days"), @@ -257,8 +264,14 @@ var et2_date_duration = et2_date.extend({ for(var i = 0; i < this.options.display_format.length; i++) { this.format.append(""); } - } else { - this.format = $j(document.createElement(""+this.time_formats[this.options.display_format])+"").appendTo(this.node); + } + else if (this.time_formats[this.options.display_format]) + { + this.format = $j(""+this.time_formats[this.options.display_format]+"").appendTo(this.node); + } + else + { + this.format = $j(""+this.time_formats["m"]+"").appendTo(this.node); } }, attachToDOM: function() { @@ -315,7 +328,7 @@ var et2_date_duration = et2_date.extend({ // Set unit as figured for display if(display.unit != this.options.display_format) { - if(this.format.children().length > 1) { + if(this.format && this.format.children().length > 1) { $j("option[value='"+display.unit+"']",this.format).attr('selected','selected'); } else