======
Fields
======

All items, working with database table data have a 
:doc:`fields </refs/client/item/at_fields>`
attribute - a list of field objects, which are used to represent fields in item's
table records. 

Every field have the following attributes:

.. csv-table:: 
   :header: Client, Server, Description
   :widths: 10, 10, 80

   :doc:`owner </refs/client/field/at_owner>`, :doc:`owner </refs/server/field/at_owner>`, "The item that owns this field."
   :doc:`field_name </refs/client/field/at_field_name>`, :doc:`field_name </refs/server/field/at_field_name>`, "The name of the field that will be used in programming code to get access to the field object."   
   :doc:`field_caption </refs/client/field/at_field_caption>`, :doc:`field_caption </refs/server/field/at_field_caption>`, "The name of the field that appears to users."   
   :doc:`field_type </refs/client/field/at_field_type>`, :doc:`field_type </refs/server/field/at_field_type>`, "Type of the field, one of the following values: **text**, **integer**, **float**, **currency**,  **date**, **datetime**, **boolean**, **blob**."      
   :doc:`field_size </refs/client/field/at_field_size>`, :doc:`field_size </refs/server/field/at_field_size>`, "A size of the field with type **text**"   
   :doc:`required </refs/client/field/at_required>`, :doc:`required </refs/server/field/at_required>`, "Specifies whether a nonblank value for a field is required."   


To get access to the item dataset data, the Field class have the following properties: 

.. csv-table:: 
   :header: Client, Server, Description
   :widths: 10, 10, 80

   :doc:`value </refs/client/field/at_value>`, :doc:`value </refs/server/field/at_value>`, "Use this property to get or set the field's value of the current record. When reading the value is converted to the type of the field. So for fields of type integer, float and currency, if value for this field in database table record is NULL, value of this property is 0. To get unconverted value use the raw_value property."
   :doc:`text </refs/client/field/at_text>`, :doc:`text </refs/server/field/at_text>`, "Use this property to get or set the value of the field as text."
   :doc:`lookup_value </refs/client/field/at_lookup_value>`, :doc:`lookup_value </refs/server/field/at_lookup_value>`, "Use this property to get or set lookup value, see :doc:`Lookup fields <lookup_fields>`."
   :doc:`lookup_text </refs/client/field/at_lookup_text>`, :doc:`lookup_text </refs/server/field/at_lookup_text>`, "Use this property to get or set the lookup value of the field as text, see :doc:`Lookup fields <lookup_fields>`."
   :doc:`display_text </refs/client/field/at_display_text>`, :doc:`display_text </refs/server/field/at_display_text>`, "Represents the field's value as it is displayed in data-aware controls. When the field is a lookup field it's value is the lookup_text value, otherwise it is the text value, with regard of project locale parameters. This behavior can be overriden by the :doc:`on_field_get_text </refs/client/item/on_get_field_text>` event handler of the item that owns the field."   
   :doc:`raw_value </refs/client/field/at_raw_value>`, :doc:`raw_value </refs/server/field/at_raw_value>`, "Use this property to get field value of the current record as it is stored in database. No conversion is used."      

In addition every field is an attribute of the item that owns it. So, to get 
access to a field of an item use the following syntax: ``item.field_name``

.. code-block:: js
    
    invoices.total.value  
    
``invoices.total`` is the reference to the
**Total** field of the **Invoices** item and the 
``invoices.total.value`` is the value of this field

    
Below are the values of the attributes of the fields of the **invoices** item in the 
:doc:`Demo project </intro/demo_project>`
::

  customer integer 
     value:  2
     text:  2
     lookup_value:  Köhler
     lookup_text:  Köhler
     display_text:  Leonie Köhler
  firstname integer 
     value:  2
     text:  2
     lookup_value:  Leonie
     lookup_text:  Leonie
     display_text:  Leonie
  billing_address integer
     value:  2
     text:  2
     lookup_value:  Theodor-Heuss-Straße 34
     lookup_text:  Theodor-Heuss-Straße 34
     display_text:  Theodor-Heuss-Straße 34
  id integer
     value:  1
     text:  1
     lookup_value:  None
     lookup_text:  
     display_text:  1
  date date
     value:  2014-01-01
     text:  01/01/2014
     lookup_value:  None
     lookup_text:  
     display_text:  01/01/2014
  total currency
     value:  2.08
     text:  $2.08
     lookup_value:  None
     lookup_text:  
     display_text:  $2.08

