1

I would like to specify the date format for a new date field in my CMS page form. I have created a new cms_page_form.xml field which links to a date field in the MySQL database table cms_page. However, MySQL rejects the field because it is in the wrong format. I have tried setting the format in many different ways: https://i.imgur.com/xjtrrYc.png (also without the item options array), literally spending hours trying to set it in cms_page_form.xml with the official documentation for the Date component not providing much of any help: https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/ui-date.html

I have even tried creating my own UI component (also specifying the new component /form/element/date etc of course) with just time as an example, and just time does work: https://i.imgur.com/PhrWqcp.png however when I change it to use date and specify the custom date format in JavaScript, it still doesn't work: https://i.imgur.com/R1XuXYW.png it just uses today's date in the wrong format: https://i.imgur.com/elamryD.png

Here is my cms_page_form.xml with the date formatting not working: https://i.imgur.com/xjtrrYc.png

When I load the CMS page, by default, it displays "Invalid date": https://i.imgur.com/kVv7I2o.png then quickly changes over to today's date - in the wrong format: https://i.imgur.com/OcfoH0E.png

All I want is a date input with the format of yyyy-MM-dd in my CMS page form in Magento 2.4.2

If anyone could help me with this I would really appreciate it.

Thanks.

1 Answer 1

0

add date Format

<column name="run_time" class="Magento\Ui\Component\Listing\Columns\Date">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="filter" xsi:type="string">dateRange</item>
            <item name="sortOrder" xsi:type="number">60</item>
            <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
            <item name="dataType" xsi:type="string">date</item>
            <item name="label" xsi:type="string" translate="true">Run Time</item>
            <item name="dateFormat" xsi:type="string" translate="true">MM/dd/YYYY hh:mm:ss a</item>
        </item>
    </argument>
</column>

Now delete the records that you find from a ui_bookmark table.

Clear the cache

See more: https://www.screencast.com/t/qePBLRpe27

1
  • At first I tried copying just the date format but it didn't change the date format it was still the same, then I tried copying the argument block and it didn't work it threw an error about uid is not defined, then I tried copying the class type as well and it still threw a slightly different error about uid is not defined: i.imgur.com/lZAYWR9.png When copying the entire column block, it says that column is not allowed here (in my cms_page_form.xml): i.imgur.com/rb6ndXa.png
    – drgandynt
    Jan 6 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.