简体   繁体   English

Magento前端类型限制

[英]Magento frontend type restriction

I want to restrict the type of a text field for magento backend custom variable to int. 我想将magento后端自定义变量的文本字段类型限制为int。 There doesn't seems to be any type qualifying for it. 似乎没有任何符合条件的类型。 The closest one is text. 最接近的是文本。 I was thinking of restricting by using a combination of frontend type and model; 我当时想通过结合使用前端类型和模型来进行限制。 however it seems like a lot of work, just to restrict the type to int. 但是,将类型限制为int似乎需要做很多工作。 Is there any better solution for the same? 有没有更好的解决方案呢?

I found the answer. 我找到了答案。 It is to add a validate tag in the field definition. 这是在字段定义中添加一个validate标签。 The validate tag can validate all kind of values. validate标签可以验证所有类型的值。 In my case it is: 以我为例:

<validate>validate-digits</validate>

the complete solution would be: 完整的解决方案是:

<fields>
     <field_name translate="label">
          <label>Field Label</label>
          <frontend_type>text</frontend_type>
          <validate>validate-digits</validate>
          <show_in_default>1</show_in_default>
          <show_in_website>0</show_in_website>
          <show_in_store>0</show_in_store>
      </field_name>
</fields>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM