[Catalyst] No database defaults with FormHandler and DBIC

Martin Rehak ligi at tekkirk.org
Mon Oct 31 07:57:23 GMT 2016


Hello,

I have a Catalyst app with generated Result class from PostgreSQL database:

...
=head2 capacity

  data_type: 'integer'
  default_value: 1
  is_nullable: 1
...

and

package reha::Form::LessonDetail;
use utf8;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Model::DBIC';
extends 'reha::Form::Base';

has '+item_class' => (default => 'Lesson');
has_field 'capacity' => (type => 'PosInteger',
        #default => '1',
        label => 'Kapacita');
...

and 

package reha::Controller::Lesson;
use Moose;
use namespace::autoclean;
use utf8;

BEGIN { extends 'Catalyst::Controller'; }

has 'formDetail' => (isa => 'reha::Form::LessonDetail', is => 'rw', lazy => 1,
        default => sub {reha::Form::LessonDetail->new });

sub detail :Local :Does('Output') :Does('AuthAdmin') {
        my ($self, $c, $lesson_id) = @_;

        $validated = $self->formDetail->process(
                item_id => $lesson_id,
                schema => $c->model('DB')->schema,
                params => $c->req->parameters);

        if ($validated) {
                $c->log->info("Form processed, data saved");
        } else {
                $c->log->error("Validation failed, data have errors");
        }

        $c->stash(template => 'template/lessonDetail.tt', form => $self->formDetail);
}
...

I have tried number of different approaches I have find on cpan.org around but
none of them renders default value of '1' into the field of 'capacity'. I would
really like to have defaults going from database schema. I suspect
reha::Form::LessonDetail->new does not return an object with pre-filled
defaults. Should that work? If not, what am I doing wrong, please?

Thank you very much for your time.

Regards
-- 
Martin Rehak



More information about the Catalyst mailing list