From: Kennedy Clark Date: Sun, 1 Jun 2008 12:18:37 +0000 (+0000) Subject: Add select to form and comments to config file X-Git-Tag: v5.8005~289 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Manual.git;a=commitdiff_plain;h=9cb64a37c49966511f9435ac99c7473b287cae79 Add select to form and comments to config file --- diff --git a/lib/Catalyst/Manual/Tutorial/AdvancedCRUD/FormFu.pod b/lib/Catalyst/Manual/Tutorial/AdvancedCRUD/FormFu.pod index ecee070..66d95a7 100644 --- a/lib/Catalyst/Manual/Tutorial/AdvancedCRUD/FormFu.pod +++ b/lib/Catalyst/Manual/Tutorial/AdvancedCRUD/FormFu.pod @@ -137,7 +137,20 @@ following method: # Return to the books list $c->response->redirect($c->uri_for('list')); $c->detach; - } + } else { + # Get the authors from the DB + my @authorObjs = $c->model("DB::Authors")->all(); + # Create an array of arrayrefs where each arrayref is an author + my @authors; + foreach (sort {$a->last_name cmp $b->last_name} @authorObjs) { + push(@authors, [$_->id, $_->last_name]); + } + # Get the select added by the config file + my $select = $form->get_element({type => 'Select'}); + # Add the authors to it + $select->options(\@authors); + } + # Set the template $c->stash->{template} = 'books/fu_form_create.tt2'; } @@ -155,11 +168,15 @@ Then create the file C and enter the following text: --- + # indicator is the field that is used to test for form submission indicator: submit + # Start listing the form elements elements: + # The first element will be a text field for the title - type: Text name: title label: Title + # This is an optional 'mouse over' title pop-up attributes: title: Enter a book title here - type: Text @@ -167,6 +184,7 @@ following text: label: Rating attributes: title: Enter a rating between 1 and 5 here + # The submit button - type: Submit name: submit value: Submit @@ -263,18 +281,26 @@ Open C in your editor and update it to match: --- + # indicator is the field that is used to test for form submission indicator: submit + # Start listing the form elements elements: + # The first element will be a text field for the title - type: Text name: title label: Title + # This is an optional 'mouse over' title pop-up attributes: title: Enter a book title here + # Add constraints for the field constraints: + # The user cannot leave this field blank - Required + # Force the length to be between 2 and 30 chars - type: Length min: 2 max: 30 + # Override the default of 'Invalid input' message: Length must be between 2 and 30 characters - type: Text name: rating @@ -283,10 +309,13 @@ to match: title: Enter a rating between 1 and 5 here constraints: - Required + # Make sure it's a number - Integer + # The submit button - type: Submit name: submit value: Submit + # Globally ensure that each field only specified one value constraints: - SingleValue