4

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

5

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, privacy policy and cookie policy

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