Index: trunk/extensions/SemanticFormsInputs/libs/datepicker.js |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | inputShow.after( resetbutton ); |
58 | 58 | resetbutton.click( function(){ |
59 | 59 | inputShow.datepicker( 'setDate', null); |
60 | | - }) |
| 60 | + }); |
61 | 61 | } |
62 | 62 | |
63 | 63 | inputShow.datepicker( { |
— | — | @@ -76,10 +76,6 @@ |
77 | 77 | 'beforeShowDay': function ( date ) {return SFI_DP_checkDate( '#' + input_id + '_show', date );} |
78 | 78 | } ); |
79 | 79 | |
80 | | - if ( ! params.partOfDTP ) { |
81 | | - inputShow.datepicker( 'option', 'altField', input ); |
82 | | - } |
83 | | - |
84 | 80 | if ( params.minDate ) { |
85 | 81 | inputShow.datepicker( 'option', 'minDate', |
86 | 82 | jQuery.datepicker.parseDate( 'yy/mm/dd', params.minDate, null ) ); |
— | — | @@ -144,14 +140,23 @@ |
145 | 141 | } |
146 | 142 | } |
147 | 143 | |
148 | | - // delete date when user deletes input field |
149 | | - inputShow.change(function() { |
| 144 | + if ( ! params.partOfDTP ) { |
150 | 145 | |
151 | | - if ( this.value == '' ) { |
152 | | - inputShow.datepicker( 'setDate', null ); |
153 | | - } |
154 | | - |
155 | | - }); |
| 146 | + inputShow.datepicker( 'option', 'altField', input ); |
| 147 | + |
| 148 | + // when the input loses focus set the date value |
| 149 | + inputShow.change( function(){ |
| 150 | + // try parsing the value |
| 151 | + try { |
| 152 | + var value = jQuery.datepicker.parseDate( params.dateFormat, this.value, null ); |
| 153 | + input.val( jQuery.datepicker.formatDate( 'yy/mm/dd', value ) ); |
| 154 | + } catch ( e ) { |
| 155 | + // value does not conform to specified format |
| 156 | + // just return the value as is |
| 157 | + input.val( this.value ); |
| 158 | + } |
| 159 | + }); |
| 160 | + } |
156 | 161 | } |
157 | 162 | } |
158 | 163 | |