bcardarella/client_side_validations — pull request #540 by vkill (2013-05-20 15:41:44+00:00)
Title: exports javascript validateElement method

Then, we can define `validateAttribute` method, used in the [x-editable validate](http://vitalets.github.io/x-editable/docs.html) and more.

```coffscript
ClientSideValidations = @ClientSideValidations
ClientSideValidations.RecordValidators ||= {}

ClientSideValidations.validateAttribute = (resourceName, attribute, elementOrString, options={}) ->
validatorsHash = options.validatorsHash || ClientSideValidations.RecordValidators[resourceName]?[attribute]
return unless validatorsHash?

if typeof(elementOrString) == 'string'
element = $("").val(elementOrString).attr
id: "#{resourceName}_#{attribute}"
name: "#{resourceName}[#{attribute}]"
else
element = elementOrString

element.on 'element:validate:before.ClientSideValidations', (e)->
options.beforeFunc?()

element.on 'element:validate:pass.ClientSideValidations', (e)->
options.passFunc?()

element.on 'element:validate:fail.ClientSideValidations', (e, message)->
options.failFunc?(message)

element.on 'element:validate:after.ClientSideValidations', (e)->
options.afterFunc?()

ClientSideValidations.validateElement(element, validatorsHash)
```