[Catalyst-commits] r7315 - in trunk/examples/Advent07FormFu/final/Fu: . lib/Fu/Controller root/forms/person

zamolxes at dev.catalyst.perl.org zamolxes at dev.catalyst.perl.org
Wed Dec 19 22:33:18 GMT 2007


Author: zamolxes
Date: 2007-12-19 22:33:17 +0000 (Wed, 19 Dec 2007)
New Revision: 7315

Modified:
   trunk/examples/Advent07FormFu/final/Fu/Makefile.PL
   trunk/examples/Advent07FormFu/final/Fu/lib/Fu/Controller/Person.pm
   trunk/examples/Advent07FormFu/final/Fu/root/forms/person/add.yml
Log:
some touches


Modified: trunk/examples/Advent07FormFu/final/Fu/Makefile.PL
===================================================================
--- trunk/examples/Advent07FormFu/final/Fu/Makefile.PL	2007-12-19 13:55:17 UTC (rev 7314)
+++ trunk/examples/Advent07FormFu/final/Fu/Makefile.PL	2007-12-19 22:33:17 UTC (rev 7315)
@@ -7,6 +7,8 @@
 requires 'Catalyst::Plugin::ConfigLoader';
 requires 'Catalyst::Plugin::Static::Simple';
 requires 'Catalyst::Action::RenderView';
+requires 'Catalyst::Controller::HTML::FormFu' => '0.02000';
+requires 'HTML::FormFu' => '0.02002';
 requires 'YAML'; # This should reflect the config file format you've chosen
                  # See Catalyst::Plugin::ConfigLoader for supported formats
 catalyst;

Modified: trunk/examples/Advent07FormFu/final/Fu/lib/Fu/Controller/Person.pm
===================================================================
--- trunk/examples/Advent07FormFu/final/Fu/lib/Fu/Controller/Person.pm	2007-12-19 13:55:17 UTC (rev 7314)
+++ trunk/examples/Advent07FormFu/final/Fu/lib/Fu/Controller/Person.pm	2007-12-19 22:33:17 UTC (rev 7315)
@@ -37,14 +37,18 @@
 
 sub edit : Local FormConfig('person/add.yml') {
   my ($self, $c, $id) = @_;
+
   $id =~ /\d+/ or die 'invalid id';
-  $c->stash->{person} = $c->model('DB::Person')->find($id) or die "person $id not found";
+  my $person = $c->stash->{person} = $c->model('DB::Person')->find($id) or die "person $id not found";
+
+  my $form = $c->stash->{form};
   
-  $c->stash->{form}->values_from_model($c->stash->{person});
 
-  if ($c->stash->{form}->submitted_and_valid) {
-    $c->stash->{form}->save_to_model($c->stash->{person});
-    $c->response->redirect($c->uri_for('/'));
+  if ($form->submitted_and_valid) {
+    $form->save_to_model($person);
+    $c->response->redirect($c->uri_for('/')); $c->detach;
+  } elsif (! $form->submitted ) {
+    $form->defaults_from_model($person);
   }
 
 }
@@ -58,10 +62,11 @@
 sub add : Local FormConfig {
   my ($self, $c) = @_;
   
-  if ($c->stash->{form}->submitted_and_valid) {
+  my $form = $c->stash->{form};
+  if ($form->submitted_and_valid) {
     my $person = $c->model('DB::Person')->new_result({});
-    $c->stash->{form}->save_to_model($person);
-    $c->response->redirect($c->uri_for('/'));
+    $form->save_to_model($person);
+    $c->response->redirect($c->uri_for('/')); $c->detach;
   }
 }
 

Modified: trunk/examples/Advent07FormFu/final/Fu/root/forms/person/add.yml
===================================================================
--- trunk/examples/Advent07FormFu/final/Fu/root/forms/person/add.yml	2007-12-19 13:55:17 UTC (rev 7314)
+++ trunk/examples/Advent07FormFu/final/Fu/root/forms/person/add.yml	2007-12-19 22:33:17 UTC (rev 7315)
@@ -1,23 +1,27 @@
 ---
 indicator: submit
 auto_fieldset: { legend : 'Person information' }
+
 elements:
   - type: Text
     name: name
     label: Name
     constraints: 
       - Required
+
   - type: Text
     name: email
     label: Email
     constraints: 
       - Required
       - Email
+
   - type: Text
     name: phone
     label: Phone
     constraints: 
       - Required
+
   - type: Radiogroup
     label: Boy or girl? :)
     name: gender
@@ -27,8 +31,10 @@
       - [ 'f', 'F' ]
     constraints: 
       - Required
+
   - type: Submit
     name: submit
     value: OK
-    constraints:
-      - SingleValue
+
+constraints:
+  - SingleValue




More information about the Catalyst-commits mailing list