# vim: sw=3 ts=3 ft=org

#+TITLE: Event Action Element
#+STYLE: <LINK href='../stylesheet.css' rel='stylesheet' type='text/css' />
#+AUTHOR: Rusty Klophaus (@rustyio)
#+OPTIONS:   H:2 num:1 toc:1 \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
#+EMAIL: 
#+TEXT: [[file:../index.org][Getting Started]] | [[file:../api.org][API]] | [[file:../elements.org][Elements]] | [[file:../actions.org][*Actions*]] | [[file:../validators.org][Validators]] | [[file:../handlers.org][Handlers]] | [[file:../config.org][Configuration Options]] | [[file:../about.org][About]]

* Event Action - #event {}

  This action tells Nitrogen to listen for a client side
  event, and take some action when the event is triggered.

  An event action can trigger a postback to the server, a block of Javascript,
  other actions, or any combination of the three.

  If the 'postback' attribute is defined, the page will post back to the event/1 function
  with the postback value as the sole attribute. This postback value can be any Erlang term.

  If the 'actions' attribute is set (inherited from action base), then these actions will
  be run when this event is triggered. This attributed can be set to a list of actions, a single
  action, or an Erlang string, which will be run as Javascript.

  Within the Javascript, you can use obj('id') where id is the id of a Nitrogen element. You can
  also use obj('me') to refer to the target of the current action.

** Usage

#+BEGIN_SRC erlang
   wf:wire(myDiv1, #event { type=click, actions=#confirm { text="Are you sure?", postback=continue } })
#+END_SRC

#+BEGIN_SRC erlang
   wf:wire(myDiv2, #event { type=click, postback={clicked, myDiv2} })
#+END_SRC

** Attributes

   + type - (/atom/) :: Type of the event, can be any Javascript-able event, such as 'click', 'mouseover', 'mouseout', etc. Or, set to 'timer' to automatically call the event after a certain period of time.

   + delay - (/integer/) :: Use along with type of 'timer'. Milliseconds to delay before calling the event.

   + postback - (/Erlang term/) :: When this event fires, Nitrogen will initiate an event postback with the supplied term.

   + delegate - (/atom/) :: Delegate is the name of the module that will receive this event. Default to the current page.

** Callbacks

*** event(Tag)

    Called when the event is fired. Tag is specified in the 'postback' attribute.

** See Also

   + [[./base.html][base element]]

 
