Magento 2 Admin Form – Using Input Type Number

adminformmagento2

I try to add input field type number for magento 2 by using \Magento\Backend\Block\Widget\Form\Generic in backend like this:

$fieldset->addField(
            'sorting_order',
            'number',
            array(
                'name' => 'sorting_order',
                'label' => __('Sort Order'),
                'title' => __('Sort Order'),
                'required' => false,
            )
);

when i try to load the form, it will not render the input field type number and make the form and other input fields do not render at all, but when i change the number to text, it will render the input as type text and the form fine

Best Answer

Try this code :-

$fieldset->addField(
            'sorting_order',
            'text',
            array(
                'name' => 'sorting_order',
                'label' => __('Sort Order'),
                'title' => __('Sort Order'),
                'required' => false,
                'class' => 'validate-number'
            )
);
Related Topic