Magento 1.8 Date Validation Conflict with Date Picker – Troubleshooting Guide

datemagento-1.8validation

Following issue wiht 1.8 CE:

enter image description here

When I’m trying to save CMS custom design info:

  • Custom Design From
  • Custom Design To

The validation fails ( even if dates are correct )

  • I’m trying with chrome
  • I have tried to change switch my locale (english/italian) but same issue

The root of the problem looks to be the following one:

Date picker fill dates in the format DD/MM/YYYY but validator.js (line 503) fail to create the new date(v) obj.
It looks like date(string) accept only date in the English/American format (MM/DD/YYYY)

Any idea how to fix this ?

I'm looking for a workaround as I'm developing an extension …

Reference:

Inchoo: Magento: Date format troubles

Update

Some code may help to understand the scenario:

 $dateFormatIso = Mage::app()->getLocale()->getDateFormat(
        Mage_Core_Model_Locale::FORMAT_TYPE_SHORT
    );

    $fieldset->addField('date_from', 'date', array(
        'name'      => 'date_from',
        'label'     => Mage::helper('myhelper')->__('Date From'),
        'image'     => $this->getSkinUrl('images/grid-cal.gif'),
        'format'    => $dateFormatIso,
        'class'     => 'validate-date validate-date-range date-range-date-from'
    ));

    $fieldset->addField('date_to', 'date', array(
        'name'      => 'date_to',
        'label'     => Mage::helper('myhelper')->__('Date To'),
        'image'     => $this->getSkinUrl('images/grid-cal.gif'),
        'format'    => $dateFormatIso,
        'class'     => 'validate-date validate-date-range date-range-date-to'
    ));

Best Answer

It looks the above issue is only related to the SHORT date format, so a workaround is to set the format to something different.

For example the above code looks 'fix' the issue:

    $dateFormatIso = Mage::app()->getLocale()->getDateFormat(
        Mage_Core_Model_Locale::FORMAT_TYPE_LONG
    );

Probably the short format is something 'ambiguous' for the js Date function

Related Topic