Magento 前端类型限制

Magento frontend type restriction

我想将 magento 后端自定义变量的文本字段类型限制为 int。似乎没有任何类型符合它的条件。最接近的是文本。我正在考虑通过结合使用前端类型和模型来进行限制;然而,似乎需要做很多工作,只是将类型限制为 int。有没有更好的解决方案?

我找到了答案。就是在字段定义中添加一个validate标签。 validate 标签可以验证所有类型的值。在我的例子中是:

<validate>validate-digits</validate>

完整的解决方案是:

<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>