[英]Extjs validate Panel in Window
Available: Ext.form.Panel : 可用: Ext.form.Panel :
this.myForm = Ext.create("Ext.form.Panel", {
items : [{
xtype : 'textfield',
name : 'val1',
fieldLabel : 'val1',
allowBlank: false,
validator : function(value) { // validate val1
if (!(/^[a-zA-Z]+[\w]*$/.test(value)))
return "val1 is not valid";
return true;
}
}, {
xtype : 'textfield',
name : 'code',
fieldLabel : 'val2',
allowBlank: false,
validator : function(value) { // validate val2
if (!(/^[a-zA-Z]+[\w]*$/.test(value)))
return "val2 is not valid";
return true;
}
}]
});
then transmits it to the Window: 然后将其传输到窗口:
Ext.window.Window : Ext.window.Window :
this.someWindow = Ext.create("Ext.window.Window", { items : [me.myForm, me.anotherPanel], title : 'test', closeAction : 'hide', buttons : [{ text : 'Save', handler : function() { // some actions }
How can I validate val1 and val2 in myForm from someWindow on action: save? 如何在进行操作时从someWindow验证myForm中的 val1和val2:保存?
this will call the validator functions 这将调用验证器功能
handler: function(button) {
var valid = button.up('window').down('form').getForm().isValid();
if(valid) {
...
}
}
EDIT: 编辑:
Or you move the save button into the form buttons
config and add the option formBind: true
to the button. 或者,您将保存按钮移到表单buttons
config中,然后将选项formBind: true
添加到按钮。 this will disable the button as long as the form is invalid. 只要表格无效,这将禁用该按钮。
Those validator
functions will validate the values as the user types, so those are sufficient for client-side validation. 这些validator
功能将根据用户类型验证值,因此这些值足以进行客户端验证。 However, you will also want to have server-side validation of these values, since javascript can easily be modified client-side by a user who knows what they're doing. 但是,您还需要对这些值进行服务器端验证,因为知道自己正在做什么的用户可以很容易地在客户端修改javascript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.