Reputation: 198188
I use extjs2.x created a form:
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'
}]
});
When I leave the field blank and submit the form, it will have a red '!' on the right side, and if I move the cursor on it, it will show a message "Name should not be null".
But what I want is to alert it. How to get the current error message of the first invalid field and alart it? I checked the API doc and searched on google, but not lucky.
Upvotes: 2
Views: 11052
Reputation: 6621
Please check this solution posted by Animal. It is very nice and powerful code (can do much more you need, but will give you ideas).
There are versions for Extjs 3.x and 4.x.
Upvotes: 0
Reputation: 16130
Here you are:
form.items.each(function(x) {
if (x.validate === undefined) {
return;
}
x.validate();
alert(x.getActiveError());
});
This works in Ext 4.0 and 3.4 at least. I don't have older version to check it.
Upvotes: 7