Skip to content
Browse files

add 'control_div' tag to Simple wrapper

  • Loading branch information...
1 parent 61b5d12 commit edf55ecdfa4dc5dacdbe2d93f6919eb818f5d873 @gshank committed Feb 9, 2013
Showing with 11 additions and 6 deletions.
  1. +2 −1 lib/HTML/FormHandler/Field/Repeatable.pm
  2. +4 −0 lib/HTML/FormHandler/Widget/Wrapper/Simple.pm
  3. +5 −5 t/repeatable/js.t
View
3 lib/HTML/FormHandler/Field/Repeatable.pm
@@ -129,7 +129,8 @@ This might be useful if the form is being re-presented to the user.
Saves information in the form for javascript to use when adding repeatable elements.
If using the example javascript, you also must set 'do_wrapper' in the
-Repeatable field and use the Bootstrap widget wrapper.
+Repeatable field and use the Bootstrap widget wrapper (or wrap the repeatable
+elements in a 'controls' div by setting tags => { control_div => 1 }.
See t/repeatable/js.t for an example. See also
L<HTML::FormHandler::Render::RepeatableJs> and L<HTML::FormHandler::Field::AddElement>.
View
4 lib/HTML/FormHandler/Widget/Wrapper/Simple.pm
@@ -70,8 +70,12 @@ sub wrap_field {
if $self->do_label;
# append 'before_element'
$output .= $self->get_tag('before_element');
+ # start control div
+ $output .= qq{\n<div class="controls">} if $self->get_tag('control_div');
# the input element itself
$output .= "\n$rendered_widget";
+ # end control div
+ $output .= "\n</div>" if $self->get_tag('control_div');
# the 'after_element'
$output .= $self->get_tag('after_element');
# the error messages
View
10 t/repeatable/js.t
@@ -10,15 +10,15 @@ use HTML::FormHandler::Test;
extends 'HTML::FormHandler';
with 'HTML::FormHandler::Render::RepeatableJs';
- # Note: if using RepeatableJs, repeatable must use Bootstrap wrapper
- # but other wrappers can be 'Simple'
+ # Note: if using RepeatableJs, repeatable elements must be
+ # wrapped in a 'controls' div (like the Bootstrap wrapper)
# set 'setup_for_js' flag
# do_wrapper is turned on by 'setup_for_js' flag
has_field 'foo' => (
type => 'Repeatable',
setup_for_js => 1,
- widget_wrapper => 'Bootstrap',
do_wrapper => 1,
+ tags => { control_div => 1 },
);
# The 'remove' doesn't have to be a display field. It could be other html associated
@@ -62,7 +62,7 @@ my $rendered = $form->field('add_element')->render;
is_html( $rendered, $expected, 'add_element rendered ok' );
$expected = '
-<div class="control-group" id="foo">
+<fieldset id="foo">
<div class="controls">
<div class="hfh-repinst" id="foo.0">
<span class="btn rm_element" data-rep-elem-id="foo.0">Remove</span>
@@ -76,7 +76,7 @@ $expected = '
</div>
</div>
</div>
-</div>';
+</fieldset>';
$rendered = $form->field('foo')->render;
is_html( $rendered, $expected, 'repeatable field renders ok' );

0 comments on commit edf55ec

Please sign in to comment.
Something went wrong with that request. Please try again.