开发者

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

开发者 https://www.devze.com 2023-04-12 08:24 出处:网络
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 serv

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

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('field开发者_如何学PythonId').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.


Get the error message from the server

Ext.getCmp('your_form_id').getForm().findField('field_id_or_field_name').markInvalid('server_error_message');


I have been able to find a solution for this.

In case of server side validation failing, following needs to be returned from the server:

success:false,
errors:{
    field1:errorMsg1,
    field2:errorMsg2
}

This will itself mark the fields as invalid and apply the red-border to the fields if there is an error associated.

Hope this helps someone looking for something similar.


Instead of markInvalid function use setActiveError if you want to change error message too.

Ext.getCmp('your_component_id').setActiveError('your_custom_error_message')


Try this , it's about the server validation , you can use json or xml http://dev.sencha.com/deploy/ext-4.1.0-gpl/examples/form/xml-form.html


Ext.getCmp('#fieldId').isValid();

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号