2

I have a custom form, created via Ui Component form holiday_form.xml and after searching how to create a date component, it gives me a JS error that a can't get to work, if i change to input format, the field is rendered correctly with correct values.

Code from holiday_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
    <item name="js_config" xsi:type="array">
        <item name="provider" xsi:type="string">holiday_form.holiday_form_data_source</item>
        <item name="deps" xsi:type="string">holiday_form.holiday_form_data_source</item>
    </item>
    <item name="label" xsi:type="string" translate="true">Holiday Information</item>
    <item name="config" xsi:type="array">
        <item name="dataScope" xsi:type="string">data</item>
        <item name="namespace" xsi:type="string">holiday_form</item>
    </item>
    <item name="template" xsi:type="string">templates/form/collapsible</item>
    <item name="buttons" xsi:type="array">
        <item name="back" xsi:type="string">Dufry\Entities\Block\Adminhtml\Holiday\Edit\BackButton</item>
        <item name="delete" xsi:type="string">Dufry\Entities\Block\Adminhtml\Holiday\Edit\DeleteButton</item>
        <item name="reset" xsi:type="string">Dufry\Entities\Block\Adminhtml\Holiday\Edit\ResetButton</item>
        <item name="save" xsi:type="string">Dufry\Entities\Block\Adminhtml\Holiday\Edit\SaveButton</item>
        <item name="save_and_continue" xsi:type="string">Dufry\Entities\Block\Adminhtml\Holiday\Edit\SaveAndContinueButton</item>
    </item>
</argument>
<dataSource name="holiday_form_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">Dufry\Entities\Model\Holiday\DataProvider</argument>
        <argument name="name" xsi:type="string">holiday_form_data_source</argument>
        <argument name="primaryFieldName" xsi:type="string">id</argument>
        <argument name="requestFieldName" xsi:type="string">id</argument>
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="submit_url" xsi:type="url" path="dufry_entities/holiday/save"/>
            </item>
        </argument>
    </argument>
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
        </item>
    </argument>
</dataSource>
<fieldset name="holidays">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">General</item>
        </item>
    </argument>
    <field name="id">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="visible" xsi:type="boolean">false</item>
                <item name="dataType" xsi:type="string">text</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">block</item>
                <item name="dataScope" xsi:type="string">id</item>
            </item>
        </argument>
    </field>
    <field name="name">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">text</item>
                <item name="label" xsi:type="string" translate="true">Holiday Name</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="source" xsi:type="string">holidays</item>
                <item name="dataScope" xsi:type="string">name</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>
            </item>
        </argument>
    </field>
    <field name="date_from">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">string</item>
                <item name="label" xsi:type="string" translate="true">From date</item>
                <item name="formElement" xsi:type="string">date</item>
                <item name="source" xsi:type="string">holidays</item>
                <item name="dataScope" xsi:type="string">date_from</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>
                <item name="options" xsi:type="array">
                    <item name="dateFormat" xsi:type="string">yyyy-MM-dd</item>
                    <item name="timeFormat" xsi:type="string">hh:mm:ss</item>
                    <item name="showsTime" xsi:type="boolean">false</item>
                </item>
            </item>
        </argument>
    </field>
    <field name="date_to">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">string</item>
                <item name="label" xsi:type="string" translate="true">To date</item>
                <item name="formElement" xsi:type="string">date</item>
                <item name="source" xsi:type="string">holidays</item>
                <item name="dataScope" xsi:type="string">date_to</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>
                <item name="options" xsi:type="array">
                    <item name="dateFormat" xsi:type="string">yyyy-MM-dd</item>
                    <item name="timeFormat" xsi:type="string">hh:mm:ss</item>
                    <item name="showsTime" xsi:type="boolean">false</item>
                </item>
            </item>
        </argument>
    </field>
    <field name="description">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">text</item>
                <item name="formElement" xsi:type="string">wysiwyg</item>                    
                <item name="label" xsi:type="string">Description</item>
                <item name="template" xsi:type="string">ui/form/field</item>
                <item name="wysiwyg" xsi:type="boolean">true</item>
                <item name="source" xsi:type="string">holidays</item>
                <item name="dataScope" xsi:type="string">description</item>                
                <item name="rows" xsi:type="number">8</item>
            </item>
        </argument>
    </field>
    <field name="active">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="dataType" xsi:type="string">boolean</item>
                <item name="label" xsi:type="string" translate="true">Active</item>
                <item name="formElement" xsi:type="string">checkbox</item>
                <item name="source" xsi:type="string">holidays</item>
                <item name="dataScope" xsi:type="string">active</item>
                <item name="prefer" xsi:type="string">toggle</item>
                <item name="valueMap" xsi:type="array">
                    <item name="true" xsi:type="number">1</item>
                    <item name="false" xsi:type="number">0</item>
                </item>
                <item name="default" xsi:type="number">1</item>
            </item>
        </argument>
    </field>
</fieldset>

The error message is

Uncaught TypeError: utils.convertToMomentFormat is not a function
    at UiClass.prepareDateTimeFormats (date.js:175)

Any advices on what might be?

  • The problem now is ocurring on index of CMS pages, and i don't have nothing customized there. Anyone having this problem too? – KNagisa Aug 25 '17 at 18:45
1

If anyone experiences this. Make sure that you have cleared your third-party caching too (in my case it was cloudflare.com)

  • I have cleared it.. no luck! .. using elastic cache aws – Hammad Khalid Oct 10 '17 at 12:44
  • Or the browser's cache. – Jānis Elmeris Dec 12 '17 at 11:23

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.