NAME

HTML::FormFu::Role::JQueryValidation - Client-side JS constraints

SYNOPSIS

$form->roles('JQueryValidation');

In your TT template:

<!DOCTYPE HTML>
<html>
<body>
    [% form %]
    
    <script src="//js/jquery.min.js" />
    <script src="//js/jquery.validate.min.js" />
    <script>
        $("#form").validate( [% form.jquery_validation_json %] );
    </script>
</body>
</html>

DESCRIPTION

Experimental support for client-side constraints with JQuery Validation http://jqueryvalidation.org.

CONSTRAINTS

Adds constraints for the following elements:

HTML::FormFu::Element::Email
HTML::FormFu::Element::URL

Supports the following constraints on any element:

HTML::FormFu::Constraint::Email
HTML::FormFu::Constraint::Integer
HTML::FormFu::Constraint::Length
HTML::FormFu::Constraint::MaxLength
HTML::FormFu::Constraint::MinLength
HTML::FormFu::Constraint::MaxRange
HTML::FormFu::Constraint::MinRange
HTML::FormFu::Constraint::Number
HTML::FormFu::Constraint::Range
HTML::FormFu::Constraint::Required

METHODS

jquery_validation_profile

Returns a hash-ref with rules and messages keys.

jquery_validation_json

Returns jquery_validation_profile passed through "objToJson" in JSON::Any.

jquery_validation_errors

Returns a hash-ref whose keys are field names with errors, and values are arrayrefs of error messages.

jquery_validation_errors_join

Arguments: $join_string

Arguments: $start_string, $end_string

Processes the return value of jquery_validation_errors, changing each arrayref of error messages into a single string.

Given 1 argument, it is used as a separator to join the error messages. Given 2 arguments, they are used to start and end each messages.

Example: if jquery_validation_errors returned the following:

{
    foo => [
        'Error 1',
        'Error 2',
    ],
}

# jquery_validation_errors_join( "<br/>" )
# outputs
{
    foo => "Error 1<br/>Error 2"
}

# jquery_validation_errors_join( "<li>", "</li>" )
# outputs
{
    foo => "<li>Error 1</li><li>Error 2</li>"
}

SEE ALSO

HTML::FormFu

http://jqueryvalidation.org

AUTHORS

Carl Franks

LICENSE

This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.