extjs 4 - How change default message error in field

LookAtMeNow picture LookAtMeNow · Jul 27, 2013 · Viewed 19.4k times · Source

I have a form panel in http://jsfiddle.net/7CLWy/ here is my important code

items: [{
    xtype: 'textfield',
    fieldLabel: 'First Name',
    allowBlank: false,
    msgTarget: 'under',
    name: 'firstName'
}, {
    xtype: 'datefield',
    allowBlank: false,
    fieldLabel: 'Start date',
    msgTarget: 'under'
}],

I want change default message error in field

enter image description here

How to change that. Thanks

Answer

Chris Farmer picture Chris Farmer · Jul 27, 2013

The blankText property is the validation message when a field is required, and invalidText is the text when the field generically fails validation. You can add your own custom messages in these properties. Similarly, if you happened to be doing regex-based validation with the regex property, you could use the regexText field to provide a custom validation message.

    items: [{
        xtype: 'textfield',
        fieldLabel: 'First Name',
        allowBlank: false,
        msgTarget: 'under',
        name: 'firstName',
        blankText: 'This should not be blank!'
    }, {
        xtype: 'datefield',
        allowBlank: false,
        fieldLabel: 'Start date',
        msgTarget: 'under',
        invalidText: 'This value is not a valid date!'
    }, {
        xtype: 'textfield',
        fieldLabel: 'Digits followed by A,B,or C',
        msgTarget: 'under',
        name: 'someText',
        regex: /^\d+[ABC]$/,
        regexText: 'This must be a string of digits followed by A, B, or C!'
    }]