Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When auto-populating a date picker, use the date picker's format #109

Merged
merged 4 commits into from
Mar 28, 2019

Conversation

kirk-circle
Copy link
Contributor

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.

@kirk-circle
Copy link
Contributor Author

See #108 for a description of how to reproduce the bug addressed by this PR.

@mecachisenros
Copy link
Owner

@kirk-circle thank you for this, I'll review it today and get back to you.

Copy link
Owner

@mecachisenros mecachisenros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirk-circle this looks very good, thank you! I suggested some amendments before merging.

includes/class-civicrm-caldera-forms-helper.php Outdated Show resolved Hide resolved
includes/class-civicrm-caldera-forms-helper.php Outdated Show resolved Hide resolved
includes/class-civicrm-caldera-forms-helper.php Outdated Show resolved Hide resolved
includes/class-civicrm-caldera-forms-helper.php Outdated Show resolved Hide resolved
@mecachisenros mecachisenros merged commit 18c231f into mecachisenros:dev Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants