Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5489

How to add datetime type field to a custom form in Magento 2

$
0
0

In this blog we will learn how to add a datetime type field to a fieldset in custom form at admin side in Magento 2.

We will not explain here basic form creation. If you beginner then you can check this blog .

After successfully created basic form. Now you can add following code into Form.php In App/Code/Webkul/Grid/Block/Adminhtml/Grid/Edit to add datetime field.

$fieldset->addField(
    'start_date',
    'date',
    [
        'name' => 'start_date',
        'label' => __('Start Date'),
        'id' => 'start_date',
        'title' => __('Start Date'),
        'date_format' => 'yyyy-MM-dd',
        'time_format' => 'hh:mm:ss',
        'required' => true            
    ]
);

It will create a datetime type field like below in admin form,

 

Thanks for reading. Feel free to comment if you face any issue.


Viewing all articles
Browse latest Browse all 5489

Trending Articles