#39218 - Custom Date Format Not Respected #39285
Open
+2
−3
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.
Description (*)
Locale settings in Date.php:82, Magento\Ui\Component\Form\Element\DataType\Date->prepare() is overriding incoming components $config dateFormat entry.
Logs below display how custom component dateFormat xml config gets overridden in prepare() function via Locale settings. First entry is with en_US and 2nd log is with de_DE validating issue despite locale.
===============================
The dateFormat config option was not in the original steps to reproduce XML but it is the primary option used for Validation and Frontend Display via Calendar Widget and DatePicker js files, when adding dateFormat to Ui component form xml issue still occurred.
Screenshot of issue prior to applied fix:
This fix adds null coalesce check if the components config option already has a set
dateFormat
if so then do not apply system localedateFormat
for incoming component else use$this->localeDate->getDateFormat();
Additional notes:
validate-date
format to ensure proper usage.Related Pull Requests
This one
Fixed Issues (if relevant)
Manual testing scenarios (*)
Tested against i39218 module
Also tested against my own module, added Save component to store into database confirming entire process works as intended:
yyyy-MM-dd
as set in view/adminhtml/ui_component/calendar_debug_form.xml instead ofmm/dd/yyyy
as default for en_US.bin/magento setup:static-content:deploy -f de_DE && bin/magento cache:clean
yyyy-MM-dd
instead ofmm.dd.yyyy
, notice the periods in-between date groups which is default for Germany de_DE.Output after applied fix:
Also, tested against other Locale settings via My Account > Account Setting (admin) and works as expected.
Questions or comments
I was also noodling over if Magento Core should add another XML config option to the date component to display an Override Checkbox, so that the burden is off the developer to develop this configuration and allows flexibility to the end User to use the Magento locale dateFormat instead of the modules explicitly defined dateFormat.
Screenshot example:
Possible changes needed for new config proposal:
<item name="useSiteLocale" type="boolean" xsi:type="xpath">settings/useSiteLocale</item>
set to false, as this can be enabled by the developer.If this is something worth while or should be Cores responsibility, I can create a ticket. I wanted to bring this up in Slack but was not able to join. If an invite can be sent to [email protected] I can bring it up in the channel.
Contribution checklist (*)