=================
on_field_validate
=================

on_field_validate(field)

**domain**: client 

**language**: javascript

**class** :doc:`Item class </refs/client/item_api>`

Description
===========

Write an ``on_field_validate`` event handler to validate changes made to the 
field data.

The ``field`` parameter is the field whose data has been changed. To get the 
item that owns the field, use the 
:doc:`owner </refs/client/field/at_owner>` 
attribute of the field.

The event handler must return a string if the field value is invalid. 
When an event handler returns a string, the application throws an exception.

The event is triggered when the 
:doc:`post <m_post>`
method is called or when the user leaves the input used to edit the field value.

Example
=======

.. code-block:: js

    function on_field_validate(field) {
        if (field.field_name === 'sum' && field.value > 10000000) {
                return 'The sum is too big.';
        }
    }


See also
========

:doc:`Fields </programming/data/fields>`

:doc:`value </refs/client/field/at_value>`

:doc:`How to validate field value </how_to/how_to_validate_field_value>`


