The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HTML::FormHandlerX::Form::JQueryValidator - Perl trait for HTML::FormHandler and JQuery Validator

VERSION

0.05

SYNOPSIS

 use HTML::FormHandler::Moose;

 with HTML::FormHandlerX::Form::JQueryValidator;

 ...

 $form->to_jquery_validation_profile();

 ....

    <input type="hidden" id="validation_json" value="[% form.as_escaped_json %]">

    <script>
    var validationJSON = JSON.parse(decodeURIComponent($("#validation_json").val() ) );

    $("#story_form").validate({
                rules: validationJSON.rules,
                   highlight: function(label) {
                    $(label).closest('.control-group').addClass('error');
                },
                messages: validationJSON.messages,
                success: function(label) {
                    label
                        .text('OK!').addClass('valid')
                        .closest('.control-group').addClass('success');
                }
            });
     });
     </script>

DESCRIPTION

This perl role allows you to re-use some form validation rules with the JQuery Validation plugin (http://docs.jquery.com/Plugins/Validation)

METHODS

to_jquery_validation_profile

Object method, takes no arguments.

Returns as hashref holding a hash of rules and another of messages for the JQuery Validation plugin, based on the form fields of the object.

as_escaped_json

Object method, takes no arguments.

Returns the jquery validation profile as a URI escaped json string, allowing it to be stashed in a hidden form field and extracted by javascript for use with JQuery Validation plugin

SEE ALSO

http://alittlecode.com/files/jQuery-Validate-Demo/
http://docs.jquery.com/Plugins/Validation
HTML::FormHandler
Twitter Bootstrap
examples/ dir in source code

AUTHOR

Aaron Trevena, <teejay@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Aaron Trevena

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.