Magento – Datepicker in widget

datewidgets

What is the best way to create widget with a parameter with date picker?

The problem is that I did not find a good way to supply format value to Date element class.

Best Answer

Date fields don't work in widgets mainly because of this: Mage_Widget_Block_Adminhtml_Widget_Options::_addField() - this is the method that renders the options.
The date for the widget option looks like this:

    $data = array(
        'name'      => $form->addSuffixToName($fieldName, 'parameters'),
        'label'     => $this->_translationHelper->__($parameter->getLabel()),
        'required'  => $parameter->getRequired(),
        'class'     => 'widget-option',
        'note'      => $this->_translationHelper->__($parameter->getDescription()),
    );

So even if you specify a format in your xml it will be ignored.
Rewrite the method above and add change the code above to:

    $data = array(
        'name'      => $form->addSuffixToName($fieldName, 'parameters'),
        'label'     => $this->_translationHelper->__($parameter->getLabel()),
        'required'  => $parameter->getRequired(),
        'class'     => 'widget-option',
        'note'      => $this->_translationHelper->__($parameter->getDescription()),

    );
    if ($parameter->getType() == 'date') {
        'format'    => $parameter->getFormat(),
        'image'     => $this->getSkinUrl('images/grid-cal.gif'),
    }

And this still won't get it to work. I mean the field will appear but the calendar doesn't work. I haven't figured out yet why.

Related Topic