我使用extjs2.x创建了一个表单:
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var form = new Ext.form.FormPanel({
items: [{
xtype: 'textfield',
xtype: 'textfield',
name: 'name',
anchor: '95%',
fieldLabel: '<span style="color:red">*</span> Name',
allowBlank: false,
blankText: 'Name should not be null'
}]
});
当我将该字段留空并提交表单时,它将显示为红色'!'在右侧,如果我将光标移到它上面,它将显示一条消息“名称不应该为空”。
但我想要的是提醒它。如何获取第一个无效字段和alart的当前错误消息呢?我检查了API文档并在谷歌搜索,但不幸运。
答案 0 :(得分:7)
你在这里:
form.items.each(function(x) {
if (x.validate === undefined) {
return;
}
x.validate();
alert(x.getActiveError());
});
至少在Ext 4.0和3.4中有效。我没有旧版本来检查它。
答案 1 :(得分:0)
请查看Animal发布的this解决方案。它是非常好的和强大的代码(可以做更多你需要的,但会给你的想法) 有Extjs 3.x和4.x的版本。