Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS 4 - How to mark form field invalid and display red borders around it (as done default by ExtJS) if custom validation fails?

enter image description here

I have a form in which some of the fields need to be validated at the server side.

When the form is submitted, then the server validates the values of these fields and if validations fail then server returns success:false (along with name and error message of each field at which validation has failed).

Now, I need to display such fields as 'invalid' and apply the same red-border around them which is default done by ExtJS if client side validation failed.

I tried using the following:

Ext.getCmp('fieldId').markInvalid() and invalidCls:'x-form-invalid-field'

I used the above statements in the 'failure' callback function of form.submit. These statments get called but don't apply any effect on such fields.

Thus could anyone guide at the following:

How to mark a field invaild and apply the same effect (having red-borders) around it when a custom validation fails?

Thanks in advance.

like image 864
netemp Avatar asked Oct 11 '11 08:10

netemp


1 Answers

Get the error message from the server

Ext.getCmp('your_form_id').getForm().findField('field_id_or_field_name').markInvalid('server_error_message');
like image 188
Kld Avatar answered Sep 29 '22 12:09

Kld