ExtJS - error message

I am building an application in ExtJS and I have a form with a submit failure function as follows:

buttons:[{
 text: 'Bestil',
 id:'button_bestil',
 width:85,
 handler: function(){
  create.getForm().submit({
   success: function(f,a){
    //do stuff!
   },
   failure: function(f,a){
    Ext.Msg.alert('Fejl', 'Error');
   }
  });                     
 }
}] 

Now I want to show the cause of the error from the fields where they are not filled correctly.

Fx I have a text box with the following:

vtypeText:'Please type in valid email',
vtype:'email'

I found out that I can use a.resultType.It returns a "client". Now, how to get the actual error message.

Hope this makes sense

/ Souni

+3
source share
1 answer

From what I'm collecting, do you want to tell the user a list of all invalid fields and a reason for each?

This can be done using the code:

YOUR_FORM.getForm().items.each(function( item ) {
   if(item.getActiveError()){
    alert('Field: '+item.name+ ' Error: ' + item.getActiveError());
   }
});

Where YOUR_FORM is the name of the formpanel component that encapsulates your form.

, , - , ( ), . , , , , .

:

var ERROR_STRING;
YOUR_FORM.getForm().items.each(function( item ) {
    if(item.getActiveError()){
  ERROR_STRING=ERROR_STRING+"The field '"+item.name+ "' is invalid, reason: " + item.getActiveError() + "<br />"; 
    }
});
if(ERROR_STRING.length>0){
    Ext.MessageBox.alert('Error',ERROR_STRING);
}
+4

Source: https://habr.com/ru/post/1766291/


All Articles