FAQ
Hello,

I'm writing a Catalyst app based on the examples in the Catalyst book
(basic CRUD) and am experiencing odd behavior with FormBuilder.
I currently have a simple model with projects and clients.
I am forwarding /project/add to /project/edit.
When I directly edit a project I see formbuilder load the edit.fb once.
When I try to add a new project, I see formbuilder load the edit.fb file
twice. In 'edit' I seem to be able to dynamically set the form
properties (label for name) and create a select element from database
values. 'project/add' seems to build the form right the first time, but
seems to use defaults (edit.frb and no database values in select) the
second time. I've deduced this from the very verbose FormBuilder debug
output - it shows the same 'generated tag' three time for add, only once
(and with correct values) for edit.

thanks,

fahd

_ project/add:

[debug] "GET" request for "project/add" from "127.0.1.1"
[debug] Path is "project/add"
[debug] Form (project/edit): Looking for config file project/edit.fb
[debug] Form (project/edit): Found form config
/home/sultan/Workspace/TnTr/root/forms/project/edit.fb
[debug] Form (project/edit): Looking for config file project/edit.fb
[debug] Form (project/edit): Found form config
/home/sultan/Workspace/TnTr/root/forms/project/edit.fb
[debug] Rendering template "project/edit.tt2"

_ project/edit:

[debug] "GET" request for "project/edit/1" from "127.0.1.1"
[debug] Path is "project/edit"
[debug] Arguments are "1"
[debug] Form (project/edit): Looking for config file project/edit.fb
[debug] Form (project/edit): Found form config
/home/sultan/Workspace/TnTr/root/forms/project/edit.fb
[debug] Rendering template "project/edit.tt2"

_ root/forms/project/edit.fb :

name: project_edit
method: post
fields:
name:
label: Project Name
type: text
size: 30
required: 1
description:
label: Project Description
type: text
size: 30
required: 1
client:
label: Client
type: select
required: 1

_ TnTr::Controller::Project:

sub add : Local Form('/project/edit') {
my ($self, $c) = @_;
$c->stash->{template} = 'project/edit.tt2';
$c->forward('edit', []);
}
sub edit : Local Form {
my ($self, $c, $id) = @_;

my $form = $self->formbuilder;
my $project = $c->model('TnTrDB::Projects')->
find_or_new({id => $id});
$form->field(name => 'client',
options => [ map { [$_->id,$_->name] }
$c->model('TnTrDB::Clients')->all ],
);
$form->field(name => 'name',
label => 'Bobo',
);
if ($form->submitted && $form->validate) {
$project->name($form->field('name'));
$project->client($form->field('client'));

$project->update_or_insert;

$c->stash->{message} =
($id > 0 ? 'Updated ' : 'Added ') . $project->name;
$c->forward('list');
}
else {
if(!$id){
$c->stash->{message} = 'Adding a new Project';
$form->field(name => 'client',
options => [ map { [$_->id,$_->name] }
$c->model('TnTrDB::Clients')->all ],
);
}
else {
# only set values if exists in database
# if I don't do this catalyst blows up on add
$form->field(name => 'name',
value => $project->name);
$form->field(name => 'client',
value => $project->client->id);
}
}
}

Search Discussions

  • Tomas Doran at May 9, 2009 at 5:09 pm

    Fahd wrote:
    I've deduced this from the very verbose FormBuilder debug
    output - it shows the same 'generated tag' three time for add, only once
    (and with correct values) for edit.
    Hi.

    Unfortunately, not that many people use FormBuilder these days, the book
    is fairly dated.. :/

    I think your best course of action is to take the FormBuilder dist, and
    reduce the issue you're seeing to a failing test case.

    Currently, I couldn't guess if this is a bug in FormBuilder itself, or
    in the Catalyst controller module - if you can provide failing tests,
    then you're much more likely to get someone to fix the issue. Try
    re-posting your failing tests to the mailing list, and logging them in
    the rt.cpan queue for the relevant modules.

    If you can't / are struggling to do that for any reason, then my best
    recommendation is _still_ filing an RT against the relevant with as much
    detail as you can, and having reduced the bug to the minimum size
    possible (a TestApp showing the bug is almost as good as 'proper' test
    cases).

    Sorry I can't give you more help, but I'm not a FormBuilder user.

    Cheers
    t0m

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedMay 6, '09 at 5:07a
activeMay 9, '09 at 5:09p
posts2
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Fahd: 1 post Tomas Doran: 1 post

People

Translate

site design / logo © 2022 Grokbase