1

I want to add select field to adminhtml form to select month. I've found

\Magento\Config\Model\Config\Source\Locale\Weekdays

provider for weekdays:

    <field name="month">
        <argument name="data" xsi:type="array">
            <item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Locale\Weekdays</item>
            ...
        </argument>
    </field>

enter image description here

What provider should I use to get month selector?

0

1 Answer 1

5

Actually i don't think so magento give default functionality to drop down select month, but you can archive this by custom way

Step 1 : add below code in your UI Component file

<column name="months">
<argument name="data" xsi:type="array">
    <item name="options" xsi:type="object">Namespace\Your_Module\Model\Source\Months</item>
    <item name="config" xsi:type="array">
        <item name="filter" xsi:type="string">select</item>
        <item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
        <item name="editor" xsi:type="string">select</item>
        <item name="dataType" xsi:type="string">select</item>
        <item name="label" xsi:type="string" translate="true">Months</item>
        <item name="sortOrder" xsi:type="number">60</item>
    </item>
</argument>

Step 2 : Create a source model under Namespace\Your_Module\Model\Source

Months.php

<?php
namespace Namespace\ModuleName\Model\Source;

use Magento\Framework\Data\OptionSourceInterface;

/**
* Class Status
*/
class Months implements OptionSourceInterface
{
/**
 * Get the options
 *
 * @return array
 */
public function toOptionArray()
{
    return [
        ['label' => __('January'), 'value' => '0'],
        ['label' => __('February'), 'value' => '1'],
        ['label' => __('March'), 'value' => '2'],
        ['label' => __('April'), 'value' => '3'],
        ['label' => __('May'), 'value' => '4'],
        ['label' => __('June'), 'value' => '5'],
        ['label' => __('July'), 'value' => '6'],
        ['label' => __('August'), 'value' => '7'],
        ['label' => __('September'), 'value' => '8'],
        ['label' => __('October'), 'value' => '9'],
        ['label' => __('November'), 'value' => '10'],
        ['label' => __('December'), 'value' => '11']
    ];
}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.