Subject: | policy error in HTML::FormHandler::InitResult |
When I use HTML::FormHandler::Model::DBIC.
I has following Form:
package MyForm;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Model::DBIC';
use namespace::autoclean;
use utf8;
has '+item_class' => ( default => 'Preplan' );
has_field 'name' => ( type => 'Text' , required => 1 );
has_field 'actions' => (
type => '+MyForm::Preplan::PreplanActionShipField',
do_wrapper => 1,
do_label => 1,
required => 1,
accessor => 'preplan_preplanactionships',
);
package MyForm::Preplan::PreplanActionShipField;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Field::Repeatable';
use namespace::autoclean;
use utf8;
has_field 'delete' => (
type => 'Button',
do_wrapper => 0,
do_label => 0,
element_class => [ qw( btn btn-small btn-danger) ],
value => 'Delete',
);
has_field 'priority' => (
type => 'Integer',
element_class => [ qw(input input-small) ],
do_wrapper => 0,
do_label => 0,
required => 1,
);
================spliter======================
create form : my $form = MyForm( item => $item);
now, i found that the "delete" field also fetch from "item" ==> my
database;
which make the resultrow deleted.
what i wanna is that delete just a NoValue field, it shouldnot fetch
from database.
When i debug to the HTML::FormHandler source code. i found that the
issue is in HTML::FormHandler::InitResult, in following line.
88 my $value = $self->_get_value( $field, $item );
89 $result = $field->_result_from_object( $result, $value );
IF the Field is a NoValue Field, but $item is a DBIx::Class's resultrow,
the _get_value function in line 88 will be called.
which fetch the value from database by calling the $field->accessor,
so the $item->delete() called. hence, my resultrow was deleted !!
====OK====
I think you should check the $field's type, than do something correct.
maybe other method ? hope you fix this issue :)