NAME
HTML::FormHandler::Render::RepeatableJs - role providing method to construct repeatable javascript
VERSION
version 0.40059
SYNOPSIS
Creates jQuery javascript to add and delete repeatable elements.
Note: This is still EXPERIMENTAL. This is an EXAMPLE. Changes are very likely to occur. Javascript is not guaranteed to be best practice. It will not work on all rendered repeatables (requires wrapper with id). It is strongly suggested that you make your own role if you use it. Then you can modify it as needed. Or just write out the rep_ data to javascript variables, and write the function in javascript. This function uses a plain javascript confirmation dialog. You almost certainly want to do something else. This javascript depends on the Repeatable field having a 'controls' div class in order to position the new elements. Use the Bootstrap wrapper or the 'controls_div' tag on the Simple wrapper.
A role to be used in a Form Class:
package MyApp::Form::Test;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';
with 'HTML::FormHandler::Render::RepeatableJs';
...
DESCRIPTION
This contains one method, 'render_repeatable_js'. It's designed to be used in a template, something like:
[% WRAPPER "wrapper.tt" %]
[% form.render_repeatable_js %]
<h1>Editing Object .... </h1>
[% form.render %]
[% END -%]
It will render javascript which can be used with the AddElement field, and setting the 'setup_for_js' flag in the Repeatable field to add the ability to dynamically add a new repeatable element in a form.
Note: this code is provided as an example. You may need to write your own javascript function if your situation is different.
Some of the extra information (level) in this function is in preparation for handling nested repeatables, but it's not supported yet.
This function operates on HTML elements that have the id of the repeatable element. That requires that the wrapper have the repeatable instance ID (now rendered by default). If you don't have wrappers around your repeatable elements, this won't work.
See HTML::FormHandler::Field::AddElement for an example of rendering an HTML element that can be used to provide the AddElement button. See that field for the requirements for the add HTML.
See HTML::FormHandler::Field::RmElement for an example of rendering an HTML element that can be used to provide a 'remove' button. See that field for the requirements for the remove HTML.
NAME
HTML::FormHandler::Render::RepeatableJs
AUTHOR
FormHandler Contributors - see HTML::FormHandler
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Gerda Shank.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.