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

#+TITLE: Custom Client-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 Client-Side Validator - #js\_custom {}

  Attach a custom validator, written in Javascript, to an element. The
  validator will be executed on the client when a postback is
  triggered. Validation failure will prevent the postback.

  See [[http://livevalidation.com/documentation#ValidateCustom][Live Validation's Validate Custom]] for more information about the
  validation function and args.


** Usage

#+BEGIN_SRC erlang
   % Wire the validator against the 'my_validator' Javascript
   % function, passing in some args...
   wf:wire(ButtonID, TextBoxID, #validate { validators=[
     #js_custom { text="Validation failed.", function=my_validator, args="{ amount: 5 }" }
   ]})
#+END_SRC

** Attributes

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

   + function - (/atom or string/) :: The name of a a Javascript function that returns true if the value is valid, false if invalid.<br>function(Value, Args) -> 'true' or 'false'

   + args - (/JSON String/) :: Extra arguments passed to the custom validation function.
