I am unable to set the default value of a field on my form. I am using the following line:

   $c->stash->{object}->model->default_values( { name => 'tbz' } );

or I can break it down to this:

   my $form = $c->stash->{object};
   $form->model->default_values( { name => 'tbz' } );

But the 'name' field comes up empty when the page loads or the following error:

|"Can't locate object method "model" via package 
"NPC::Model::ModelDB::Character"
|

I know this is easy and I have researched it. Ijust can't figure out what I am doing wrong? Here is my full sub.


sub new_character : Local FormConfig('character/new_character.yml') {
 my ($self, $c) = @_;

 # load the new record object into the stash
 $c->stash->{object} = $c->model('ModelDB::Character')->new_result({});

 # Check permissions
 $c->detach('/error_noperms')
   unless $c->stash->{object}->create_allowed_by($c->user->get_object);

 # Clicked the submit button and the form passed error checking
 if ($c->stash->{form}->submitted_and_valid) {

   # Write the record to the resultset
   $c->stash->{form}->model->update($c->stash->{object});

   # Update the status message
   $c->flash->{status_msg} = 'Record created';

   # Redirect to the list_character page
   $c->response->redirect($c->uri_for('list_character'));

   # Escape this subroutine
   $c->detach;

 # First load or form is reloaded due to failing error checking
 } else {

   $c->stash->{object}->model->default_values( { name => 'tbz' } );

   # Re-evaluate the form
   $c->stash->{form}->process();

 }

# Run the code necessary to rename the repeatable elements to be compatible with wforms.js
 NPC::Controller::WForm::handle_repeat($c->stash->{form}, $c);

 # Necessary to handle the hints that work work with wforms.js
 NPC::Controller::WForm::handle_hints($c->stash->{form}, $c);

 # Set the logo
   $c->stash->{given_logo} = '/static/images/Tolkien Folder.png';

 # Set the title
 $c->stash->{given_title} = 'New Character';

 # Set the page template that is used
 $c->stash->{template} = 'standard/wform_form.tt2';

}


_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to