5

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

1 Answer 1

9

Try this code :-

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.