0

I want to allow only numbers for a certain input field in a Magento Admin Control-Table/Config-Table. Has anyone done that before or has a hint?

Greez

enter image description here

1
  • I post the updated answer, kindly check that will work for you. Commented Apr 26, 2024 at 10:57

2 Answers 2

0

You have to added validation class.

$this->addColumn('yourfieldname', ['label' => __('Your Label'),'class' => 'required-entry validate-number']);
6
  • Hey, unfortunately this didn't fix the issue. :/ Commented Apr 26, 2024 at 10:48
  • I update the code, kindly check those things. Commented Apr 26, 2024 at 10:48
  • Dhiren thank you very much, this did it for me! But now i have the Problem with the required-enty Attribute. This field should not be required but if i undo this, it won't work. Commented Apr 26, 2024 at 12:52
  • you can remove this class : required-entry then run all magento commands again and then check. Commented Apr 26, 2024 at 12:58
  • Yup, I did and it worked! Thanks again! :) Commented Apr 26, 2024 at 13:00
0

In store configuration fields, you can use below code to allow numbers only

      <config>
        <sections>
            <newsletter translate="label" module="newsletter">
                <label>Custom Label</label>
                <tab>phone</tab>
                <frontend_type>text</frontend_type>
                <sort_order>110</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <validate>validate-number</validate>
         </newsletter>
      </sections>
    </config>

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.