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
-
I post the updated answer, kindly check that will work for you.Dhiren Vasoya– Dhiren Vasoya2024年04月26日 10:57:05 +00:00Commented Apr 26, 2024 at 10:57
2 Answers 2
You have to added validation class.
$this->addColumn('yourfieldname', ['label' => __('Your Label'),'class' => 'required-entry validate-number']);
answered Apr 26, 2024 at 10:40
Dhiren Vasoya
9,70914 gold badges37 silver badges61 bronze badges
-
Hey, unfortunately this didn't fix the issue. :/TheBasicBoi– TheBasicBoi2024年04月26日 10:48:00 +00:00Commented Apr 26, 2024 at 10:48
-
I update the code, kindly check those things.Dhiren Vasoya– Dhiren Vasoya2024年04月26日 10:48:42 +00:00Commented 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.TheBasicBoi– TheBasicBoi2024年04月26日 12:52:10 +00:00Commented Apr 26, 2024 at 12:52
-
you can remove this class : required-entry then run all magento commands again and then check.Dhiren Vasoya– Dhiren Vasoya2024年04月26日 12:58:30 +00:00Commented Apr 26, 2024 at 12:58
-
Yup, I did and it worked! Thanks again! :)TheBasicBoi– TheBasicBoi2024年04月26日 13:00:53 +00:00Commented Apr 26, 2024 at 13:00
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>
answered Apr 26, 2024 at 11:00
Prashant Valanda
12.7k5 gold badges44 silver badges70 bronze badges
Explore related questions
See similar questions with these tags.
default