When auto-populating a date picker, use the date picker's format #109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This patch ensures that when a CF date picker field is auto-populated, it uses the format specified by the date picker.
Before
When a processor auto-populated a form with the logged in user's data, any date values (e.g. date of birth) being put into date pickers were being left in the format in which they were returned from the CiviCRM API, e.g. 'yyyy-mm-dd'. If the date picker specified a different format, then the date picker misread and scrambled the date value.
After
When a processor is auto-populates a form with the logged in user's data, any date values being put into date pickers are converted to the format specified by the date picker.
Technical Details
CF date pickers use a different formatting specification to the one used by PHP date functions. A new function -
translate_date_picker_format
- translates from the former to the latter.This patch only reformats dates that have been left in ISO 8601 format (the format in which dates are returned by the CiviCRM API). This is to avoid any problems that might be caused if the value has been altered, e.g. by the
cfc_filter_mapped_field_to_prerender
filter.Comments
This solution is not perfect, but it is better than before. Problems can still arise if the date picker's format includes literal text other than dashes or slashes, but in most cases it won't.