在 EXTJS 中将自定义验证作为组件
Make custom validations in EXTJS as components
我已经编写了如下自定义验证
Ext.apply(Ext.form.field.VTypes, {
valInt: function(v) {
return /^(\d+(,\d+)*)?$/.test(v);
},
valIntText: 'Must be in the form #,#',
valIntMask: /[\d\,]/i
});
有效。但我想在单个文件中进行所有此类自定义验证,然后加载或自动加载它。我该怎么做?
我可以像下面这样 app.js
Ext.onReady(function() {
Ext.apply(Ext.form.field.VTypes, {
valInt: function(v) {
return /^(\d+(,\d+)*)?$/.test(v);
},
valIntText: 'Must be in the form #,#',
valIntMask: /[\d\,]/i
});
});
但是 app.js 文件在所有验证之后会变大。
根据 documentation 您可以创建覆盖,例如:
Ext.define('Override.form.field.VTypes', {
override: 'Ext.form.field.VTypes',
valInt: function(v) {
return /^(\d+(,\d+)*)?$/.test(v);
},
valIntText: 'Must be in the form #,#',
valIntMask: /[\d\,]/i
});
在您的 app.json
中有一个 overrides
键声明覆盖目录,它看起来像:
/**
* Comma-separated string with the paths of directories or files to search. Any classes
* declared in these locations will be automatically required and included in the build.
* If any file defines an Ext JS override (using Ext.define with an "override" property),
* that override will in fact only be included in the build if the target class specified
* in the "override" property is also included.
*/
"overrides": [
"overrides",
"${toolkit.name}/overrides"
],
根据@CD..
1) 我在我的应用程序中找到了 overrides 文件夹
2) 将此 VTypes.js 文件放在 overrides 文件夹的根目录中:
Ext.override(Ext.form.field.VTypes, {
digitsOnly: function (value) {
return this.digitsOnlyRe.test(value);
},
digitsOnlyRe: /\d*$/,
digitsOnlyText: 'Use digits only!'
});
现在一切正常,thnx all
我已经编写了如下自定义验证
Ext.apply(Ext.form.field.VTypes, {
valInt: function(v) {
return /^(\d+(,\d+)*)?$/.test(v);
},
valIntText: 'Must be in the form #,#',
valIntMask: /[\d\,]/i
});
有效。但我想在单个文件中进行所有此类自定义验证,然后加载或自动加载它。我该怎么做?
我可以像下面这样 app.js
Ext.onReady(function() {
Ext.apply(Ext.form.field.VTypes, {
valInt: function(v) {
return /^(\d+(,\d+)*)?$/.test(v);
},
valIntText: 'Must be in the form #,#',
valIntMask: /[\d\,]/i
});
});
但是 app.js 文件在所有验证之后会变大。
根据 documentation 您可以创建覆盖,例如:
Ext.define('Override.form.field.VTypes', {
override: 'Ext.form.field.VTypes',
valInt: function(v) {
return /^(\d+(,\d+)*)?$/.test(v);
},
valIntText: 'Must be in the form #,#',
valIntMask: /[\d\,]/i
});
在您的 app.json
中有一个 overrides
键声明覆盖目录,它看起来像:
/**
* Comma-separated string with the paths of directories or files to search. Any classes
* declared in these locations will be automatically required and included in the build.
* If any file defines an Ext JS override (using Ext.define with an "override" property),
* that override will in fact only be included in the build if the target class specified
* in the "override" property is also included.
*/
"overrides": [
"overrides",
"${toolkit.name}/overrides"
],
根据@CD..
1) 我在我的应用程序中找到了 overrides 文件夹
2) 将此 VTypes.js 文件放在 overrides 文件夹的根目录中:
Ext.override(Ext.form.field.VTypes, {
digitsOnly: function (value) {
return this.digitsOnlyRe.test(value);
},
digitsOnlyRe: /\d*$/,
digitsOnlyText: 'Use digits only!'
});
现在一切正常,thnx all