[Jifty-commit] r1799 - jifty/trunk/lib/Jifty/Web/Form

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat Aug 12 13:15:27 EDT 2006


Author: nelhage
Date: Sat Aug 12 13:15:27 2006
New Revision: 1799

Modified:
   jifty/trunk/lib/Jifty/Web/Form/Element.pm

Log:
You can now pass confirm => 'question?' to javascript hooks (i.e. onclick) and get a confirm dialog in the browser. This doesn't work without javascript yet.

Modified: jifty/trunk/lib/Jifty/Web/Form/Element.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web/Form/Element.pm	(original)
+++ jifty/trunk/lib/Jifty/Web/Form/Element.pm	Sat Aug 12 13:15:27 2006
@@ -146,6 +146,7 @@
 
         my @fragments;
         my @actions;
+        my $confirm;
 
         for my $hook (grep {ref $_ eq "HASH"} (ref $value eq "ARRAY" ? @{$value} : ($value))) {
 
@@ -199,6 +200,11 @@
                 $args{region}  = $args{element} =~ /^#region-(\S+)/ ? "$1-".Jifty->web->serial : Jifty->web->serial;
             }
 
+            # Should we show a javascript confirm message?
+            if ($hook->{confirm}) {
+                $confirm = $hook->{confirm};
+            }
+
             # Toggle functionality
             $args{toggle} = 1 if $hook->{toggle};
 
@@ -228,6 +234,9 @@
 
             my $update = "update( ". Jifty::JSON::objToJson( {actions => \@actions, fragments => \@fragments }, {singlequote => 1}) .", this );";
             $string .= $self->javascript_preempt ? "return $update" : "$update; return true;";
+            if ($confirm) {
+                $string = "if(!confirm(" . Jifty::JSON::objToJson($confirm, {singlequote => 1}) . ")) return false;" . $string;
+            }
         }
         $response .= qq| $trigger="$string"|;
     }


More information about the Jifty-commit mailing list