8

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

LookAtMeNow
  • 261
  • 1
  • 5
  • 15
  • Did you read the docs? It's there http://docs.sencha.com/extjs/4.0.7/?mobile=/api/Ext.form.field.Base invalidText – Ruan Mendes Jul 27 '13 at 19:54

4 Answers4

18

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!'
    }]
Chris Farmer
  • 24,974
  • 34
  • 121
  • 164
0

msgTarget: 'side' will Add an error icon to the right of the field, displaying the message in a popup on hover only.

if you read the documentation carefully, one more option is there for msgTarget http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.Text-cfg-msgTarget

[element id] Add the error message directly to the innerHTML of the specified element. you have to add a "td" to the right side of the control dynamically with the id. then if you specify msgTarget: 'element id' it will work.

reference ->ExtJS4: How to show validation error message next to textbox, combobox etc

Community
  • 1
  • 1
Abdul Aleem
  • 341
  • 4
  • 14
  • sorry :( I read but I don't understand well, I try msgTarget: 'myid' and document.getElementById("myid").innerHTML='my msg';. Can you make a example working thanks – LookAtMeNow Jul 27 '13 at 16:07
0

we can use validator method and return the custom message.

{
    xtype: 'textfield',
    fieldLabel: 'Digits followed by A,B,or C',
    msgTarget: 'under',
    name: 'someText',
    validator : function(value){
         var regex= /^\d+[ABC]$/;
         if(!regex.test(value)){
              return "'This must be a string of digits followed by A, B, or C!'"
          }
         return true;
    }

}
ganesh phirke
  • 471
  • 1
  • 3
  • 12
-1

To change the default active error message we use setActiveError( msg ).you see the following code.

items: [{
        xtype: 'textfield',
        fieldLabel: 'First Name',
        allowBlank: false,
        id:'fn',
        msgTarget: 'under',
        name: 'firstName',

    }, {
        xtype: 'datefield',
        allowBlank: false,
        fieldLabel: 'Start date',
        msgTarget: 'under',
       }
    ],
renderTo: Ext.getBody()
});
var m = Ext.getCmp('fn');
m.setActiveError("important"); //can change the text
getty
  • 135
  • 11