From: Daniel Rudolf Date: Mon, 21 Jan 2013 18:43:39 +0000 (+0100) Subject: Insert a hidden element representing the date in Y-m-d format X-Git-Tag: 2.0.0_Beta_1~525^2~3^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=4209cfa01be6579496357e2c4dc911fafd168933;p=GitHub%2FWoltLab%2FWCF.git Insert a hidden element representing the date in Y-m-d format Please remember to assign the elements default value in Y-m-d format. When sending the form, the server will receive the date in the same format. --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index a7fca2a5e2..9d6d0f5548 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -2173,9 +2173,18 @@ WCF.Date.Picker = { */ _initDatePicker: function() { $('input[type=date]:not(.jsDatePicker)').each($.proxy(function(index, input) { - // do *not* use .attr() - var $input = $(input).prop('type', 'text').addClass('jsDatePicker'); + var $input = $(input); + var inputName = $input.prop('name'); + var inputValue = $input.prop('value'); // should be Y-m-d, must be interpretable by Date + + // update $input + $input.prop('type', 'text').addClass('jsDatePicker'); + + // insert a hidden element representing the actual date + $input.prop('name', inputName + 'Text') + $input.before(''); + // init date picker $input.datepicker({ changeMonth: true, changeYear: true, @@ -2183,13 +2192,21 @@ WCF.Date.Picker = { dateFormat: this._dateFormat, yearRange: '1900:2038', // TODO: make it configurable? - // language + altField: '#' + $input.prop('id') + 'DatePicker', + altFormat: 'yy-mm-dd', // PHPs strtotime() understands this best + dayNames: WCF.Language.get('__days'), dayNamesMin: WCF.Language.get('__daysShort'), dayNamesShort: WCF.Language.get('__daysShort'), monthNames: WCF.Language.get('__months'), monthNamesShort: WCF.Language.get('__monthsShort') }); + + // format default date + $input.datepicker('setDate', new Date(inputValue)); + + // bug workaround: setDate creates the widget but unfortunately doesn't hide it... + $input.datepicker('widget').hide(); }, this)); } };