[Jifty-commit] r561 -
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Feb 9 01:35:01 EST 2006
Author: jesse
Date: Thu Feb 9 01:35:01 2006
New Revision: 561
Modified:
/ (props changed)
jifty/trunk/lib/Jifty/Web/Form.pm
Log:
r23535 at truegrounds: jesse | 2006-02-09 01:34:00 -0500
* Exposing an API for finding out if we're currently inside a form
Modified: jifty/trunk/lib/Jifty/Web/Form.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form.pm (original)
+++ jifty/trunk/lib/Jifty/Web/Form.pm Thu Feb 9 01:35:01 2006
@@ -5,7 +5,7 @@
use base qw/Jifty::Object Class::Accessor/;
-__PACKAGE__->mk_accessors(qw(actions printed_actions name call));
+__PACKAGE__->mk_accessors(qw(actions printed_actions name call is_open));
=head2 new ARGS
@@ -75,6 +75,18 @@
=cut
+=head2 is_open [BOOL]
+
+This accessor returns true if Jifty is currently in the middle of rendering a form
+(if it's printed a <form> but not yet printed a </form> tag.) Use this in your
+components to decide whether to open a form or not if you might be called from a
+template that opened the form for you.
+
+=cut
+
+
+
+
=head2 add_action PARAMHASH
Calls L<Jifty::Web/new_action> with the paramhash given, and adds it to
@@ -133,6 +145,11 @@
my $self = shift;
my %args = (@_);
+
+ if ($self->is_open) {
+ Jifty->logger->warning("Trying to open a form when we already have one open");
+ }
+
for (keys %args) {
$self->$_($args{$_}) if $self->can($_);
}
@@ -141,6 +158,7 @@
$form_start .= qq! name="@{[ $self->name ]}"! if defined $self->name;
$form_start .= qq! enctype="multipart/form-data" >\n!;
Jifty->web->out($form_start);
+ $self->is_open(1);
'';
}
@@ -175,6 +193,9 @@
sub end {
my $self = shift;
+ unless ($self->is_open) {
+ Jifty->logger->warning("Trying to close a form when we don't have one open");
+ }
Jifty->web->out( qq!<div class="hidden">\n! );
$self->_print_registered_actions();
@@ -184,7 +205,7 @@
Jifty->web->out( qq!</div>\n! );
Jifty->web->out( qq!</form>\n! );
-
+ $self->is_open(0);
# Clear out all the registered actions and the name
$self->_init();
More information about the Jifty-commit
mailing list