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

#+TITLE: Custom Server-Side Validator 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]]

* Custom Server-Side Validator - #custom {}

  Attach a custom validator, written in Erlang, to an element. The validator will be executed on the server during a postback.

** Usage

#+BEGIN_SRC erlang
   % Function to validate that a value is either upper or lower case,
   % depending on the value of Tag...
   F = fun(Tag, Value) ->
     case Tag of
       upper -> string:to_upper(Value) == Value;
       lower -> string:to_upper(Value) == Value
     end
   end,
	
   % Wire the validator in upper case mode...
   wf:wire(ButtonID, TextBoxID, #validate { validators=[
     #custom { text="Must be uppercase", function=F, tag=upper }
   ]})
#+END_SRC

** Attributes

   + text - (/string/) :: The text to display if validation fails.

   + function - (/fun/) :: An Erlang function that returns true if the value is valid, false if invalid. <br>fun(Tag, Value) -> 'true' or 'false'

   + tag - (/Erlang term/) :: Tag value is passed into the custom validation function.
