=============================
How to add a button to a form
=============================

The simplest way to add a button to an edit / view from is to use
:doc:`add_edit_button </refs/client/item/m_add_edit_button>` /
:doc:`add_view_button </refs/client/item/m_add_view_button>`
correspondinly. You can call this functions in the
:doc:`on_edit_form_created </refs/client/item/on_edit_form_created>` /
:doc:`on_view_form_created </refs/client/item/on_view_form_created>`
event handlers.

For example the Customers item uses this code in its client module to add 
buttons to a view form:

.. code-block:: js

  function on_view_form_created(item) {
      item.table_options.multiselect = false;
      if (!item.lookup_field) {    
          var print_btn = item.add_view_button('Print', {image: 'icon-print'}),
              email_btn = item.add_view_button('Send email', {image: 'icon-pencil'});
          email_btn.click(function() { send_email() });
          print_btn.click(function() { print(item) });
          item.table_options.multiselect = true;
      }
  }  

In this code the item's
:doc:`lookup_field </refs/client/item/at_lookup_field>` 
attribute is checkув and if it is defined (the view form is not created to select a 
value for a lookup field) the two buttons are created and for them JQuery click 
events are assigned to ``send_email`` and ``print`` functions declared in that 
module.


