view release on metacpan or search on metacpan
1.01 2014-01-06
- don't "use" optional modules in tests
1.00 2013-12-16
- tests updated for HTML-FormFu v1.00 changes
0.09010 2012-10-05
- Support belongs_to rel with a ComboBox element.
- localize_label works with non-column label accessors.
- Add support to create required belongs_to rels (pshangov).
- options_from_model() can populate from DBIx::Class ENUM values.
- Constraint::DBIC::Unique - new id_field() and method_name() methods.
- Constraint::DBIC::Unique - others() now supports nested_names values.
- Bump required version no. of HTML-FormFu to 0.03007
0.03006 2008-12-03
- options_from_model() - If we've a Catalyst context but no schema on
the form stash, use config values for 'model' and 'resultset'
- update() - if a checkbox/radio value isn't submitted, and the column
is NOT NULL, set it to 0 (zero), not DEFAULT VALUE.
- Tests for new ComboBox element.
- Modified delete_if_true example to no longer use "delete" as a
form item name - this is bad!
0.03003 2008-08-21
- Updated to work with is_field/is_block changes in HTML-FormFu
0.03002 2008-08-11
t/constraints/dbic_unique_repeatable_id_field.t
t/constraints/dbic_unique_repeatable_id_field.yml
t/create/basic.t
t/create/basic.yml
t/default_values/basic.t
t/default_values/basic.yml
t/default_values/basic_nested.t
t/default_values/basic_nested.yml
t/default_values/belongs_to_lookup_table.t
t/default_values/belongs_to_lookup_table.yml
t/default_values/belongs_to_lookup_table_combobox.t
t/default_values/belongs_to_lookup_table_combobox.yml
t/default_values/empty_rows_zero.t
t/default_values/empty_rows_zero.yml
t/default_values/has_many_combobox.t
t/default_values/has_many_combobox.yml
t/default_values/has_many_repeatable.t
t/default_values/has_many_repeatable.yml
t/default_values/has_many_repeatable_delete_true.t
t/default_values/has_many_repeatable_delete_true.yml
t/default_values/has_many_repeatable_label.t
t/default_values/has_many_repeatable_label.yml
t/default_values/has_many_repeatable_nested.t
t/default_values/has_many_repeatable_nested.yml
t/default_values/has_many_repeatable_new.t
t/default_values/has_many_repeatable_new.yml
t/lib/MySchema/Schedule.pm
t/lib/MySchema/Task.pm
t/lib/MySchema/TwoNote.pm
t/lib/MySchema/Type.pm
t/lib/MySchema/Type2.pm
t/lib/MySchema/User.pm
t/lib/MySchema/UserBand.pm
t/lib/MySchemaRS/User.pm
t/options_from_model/belongs_to.t
t/options_from_model/belongs_to.yml
t/options_from_model/belongs_to_combobox.t
t/options_from_model/belongs_to_combobox.yml
t/options_from_model/belongs_to_config_zero.t
t/options_from_model/belongs_to_config_zero.yml
t/options_from_model/belongs_to_config_zero_combobox.t
t/options_from_model/belongs_to_config_zero_combobox.yml
t/options_from_model/belongs_to_localize_label.t
t/options_from_model/belongs_to_localize_label.yml
t/options_from_model/condition_from_stash.t
t/options_from_model/condition_from_stash.yml
t/options_from_model/condition_from_stash_combobox.t
t/options_from_model/condition_from_stash_combobox.yml
t/options_from_model/condition_from_stash_combobox_complex.t
t/options_from_model/condition_from_stash_complex.t
t/options_from_model/condition_from_stash_expand.t
t/options_from_model/condition_from_stash_expand.yml
t/options_from_model/constraint_autoset.t
t/options_from_model/constraint_autoset.yml
t/options_from_model/enum_select.t
t/options_from_model/enum_select.yml
t/options_from_model/has_many_repeatable_select.t
t/options_from_model/has_many_repeatable_select.yml
t/options_from_model/many_to_many_select.t
t/options_from_model/many_to_many_select.yml
t/options_from_model/many_to_many_select_restricted.t
t/options_from_model/many_to_many_select_restricted.yml
t/update/add_valid.t
t/update/basic.yml
t/update/basic_create.t
t/update/basic_update.t
t/update/belongs_to.t
t/update/belongs_to_combobox.t
t/update/belongs_to_create.t
t/update/belongs_to_create_required.t
t/update/belongs_to_lookup_table_combobox.t
t/update/belongs_to_lookup_table_combobox.yml
t/update/belongs_to_select.t
t/update/belongs_to_select.yml
t/update/belongs_to_select_two.yml
t/update/column_without_field.t
t/update/column_without_field.yml
t/update/has_many_repeatable.t
t/update/has_many_repeatable.yml
t/update/has_many_repeatable_delete_true.t
t/update/has_many_repeatable_delete_true.yml
t/update/has_many_repeatable_many_new.t
This method should not be called directly, but is called for you during
$form->process by fields that inherit from
HTML::FormFu::Element::_Group. This includes:
HTML::FormFu::Element::Select
HTML::FormFu::Element::Checkboxgroup
HTML::FormFu::Element::Radiogroup
HTML::FormFu::Element::ComboBox
To use you must set the appropriate resultset on the element
model_config:
element:
- type: Select
name: foo
model_config:
resultset: TableClass
empty_rows: 1
elements:
- type: Hidden
name: book
- type: Textarea
name: review_text
belongs_to relationships
Belongs-to relationships can be edited / created with a ComboBox
element. If the user selects a value with the Select field, the
belongs-to will be set to an already-existing row in the related table.
If the user enters a value into the Text field, the belongs-to will be
set using a newly-created row in the related table.
elements:
- type: ComboBox
name: author
model_config:
resultset: Author
select_column: id
text_column: name
The element name should match the relationship name.
$field->model_config->{select_column} should match the related primary
column. $field->model_config->{text_column} should match the related
text column.
lib/HTML/FormFu/Model/DBIC.pm view on Meta::CPAN
# don't follow rels to where we came from
next
if defined $attrs->{from}
&& $attrs->{from} eq $rs->related_source($rel)->result_class;
my @elements = @{ $base->get_all_elements( { nested_name => $rel } ) };
my ($block) = grep { !$_->is_field } @elements;
my ($multi_value) = grep { $_->is_field && $_->multi_value } @elements;
my ($combo) = grep { $_->isa('HTML::FormFu::Element::ComboBox') } @elements;
next if !defined $block && !defined $multi_value;
next if !$form->valid($rel);
my $params = $form->param($rel);
if ( defined $block && $block->is_repeatable ) {
# Handle has_many
_save_has_many( $self, $dbic, $form, $rs, $block, $rel, $attrs );
}
elsif ( defined $combo ) {
_save_combobox( $self, $base, $dbic, $form, $rs, $combo, $rel, $attrs );
}
elsif ( defined $block && ref $params eq 'HASH' ) {
# It seems that $dbic->$rel must be called otherwise the following
# find_related() can fail.
# However, this can die - so we're just wrapping it in an eval
eval {
$dbic->$rel;
} or $dbic->discard_changes;
my $target = $dbic->find_related( $rel, {} );
lib/HTML/FormFu/Model/DBIC.pm view on Meta::CPAN
->update( { $fkey => $dbic->$skey } );
$schema->txn_rollback
if $updated != 1;
} );
}
}
}
sub _save_combobox {
my ( $self, $base, $dbic, $form, $rs, $combo, $rel, $attrs ) = @_;
my $select = $combo->get_field({ type => 'Select' });
my $text = $combo->get_field({ type => 'Text' });
my $select_value = $form->param( $select->nested_name );
my $text_value = $form->param( $text->nested_name );
my $target_rs = $dbic->result_source->related_source( $rel )->resultset;
my $target;
lib/HTML/FormFu/Model/DBIC.pm view on Meta::CPAN
L<HTML::FormFu::Element::_Group>. This includes:
=over
=item L<HTML::FormFu::Element::Select>
=item L<HTML::FormFu::Element::Checkboxgroup>
=item L<HTML::FormFu::Element::Radiogroup>
=item L<HTML::FormFu::Element::ComboBox>
=back
To use you must set the appropriate C<resultset> on the element C<model_config>:
element:
- type: Select
name: foo
model_config:
resultset: TableClass
lib/HTML/FormFu/Model/DBIC.pm view on Meta::CPAN
empty_rows: 1
elements:
- type: Hidden
name: book
- type: Textarea
name: review_text
=head2 belongs_to relationships
Belongs-to relationships can be edited / created with a ComboBox element.
If the user selects a value with the Select field, the belongs-to will be set
to an already-existing row in the related table.
If the user enters a value into the Text field, the belongs-to will be set
using a newly-created row in the related table.
elements:
- type: ComboBox
name: author
model_config:
resultset: Author
select_column: id
text_column: name
The element name should match the relationship name.
C<< $field->model_config->{select_column} >> should match the related primary
column.
C<< $field->model_config->{text_column} >> should match the related text
t/default_values/belongs_to_lookup_table_combobox.t view on Meta::CPAN
use warnings;
use Test::More tests => 3;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/default_values/belongs_to_lookup_table_combobox.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $rs = $schema->resultset('Master');
{
my $type_rs = $schema->resultset('Type');
t/default_values/belongs_to_lookup_table_combobox.yml view on Meta::CPAN
---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: ComboBox
name: type
# set this, so options_from_model() populates the menu,
# so we can test the correct default is set
model_config:
resultset: Type
select_column: id
text_column: type
- type: ComboBox
name: type2_id
- type: Submit
name: submit
t/default_values/has_many_combobox.t view on Meta::CPAN
use warnings;
use Test::More tests => 1;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/default_values/has_many_combobox.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
{
# insert some entries we'll ignore, so our rels don't have same ids
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
t/default_values/has_many_combobox.yml view on Meta::CPAN
---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: ComboBox
name: addresses
- type: Hidden
name: count
- type: Submit
name: submit
t/lib/MySchema/Master.pm view on Meta::CPAN
is_nullable => 0,
},
text_col => { data_type => "TEXT", is_nullable => 1 },
password_col => { data_type => "TEXT", is_nullable => 1 },
checkbox_col => {
data_type => "BOOLEAN",
default_value => 1,
is_nullable => 0,
},
select_col => { data_type => "TEXT", is_nullable => 1 },
combobox_col => { data_type => "TEXT", is_nullable => 1 },
radio_col => { data_type => "TEXT", is_nullable => 1 },
radiogroup_col => { data_type => "TEXT", is_nullable => 1 },
array_col => { data_type => "TEXT", is_nullable => 1, is_array => 1 },
date_col => { data_type => "DATETIME", is_nullable => 1 },
type_id => { data_type => "INTEGER", is_nullable => 1 },
type2_id => { data_type => "INTEGER", is_nullable => 1 },
enum_col => { data_type => "ENUM", is_nullable => 1, extra => { list => [qw( a b c )] } },
not_in_form => { data_type => "TEXT", is_nullable => 1 },
);
t/options_from_model/belongs_to_combobox.t view on Meta::CPAN
use strict;
use warnings;
use Test::More tests => 2;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/belongs_to_combobox.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $type_rs = $schema->resultset('Type');
my $type2_rs = $schema->resultset('Type2');
{
t/options_from_model/belongs_to_combobox.yml view on Meta::CPAN
---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: ComboBox
name: type
model_config:
aaa : aaa
- type: ComboBox
name: type2_id
model_config:
resultset: Type2
- type: Submit
name: submit
t/options_from_model/belongs_to_config_zero_combobox.t view on Meta::CPAN
use strict;
use warnings;
use Test::More tests => 1;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/belongs_to_config_zero_combobox.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $type_rs = $schema->resultset('Type');
my $type2_rs = $schema->resultset('Type2');
{
t/options_from_model/belongs_to_config_zero_combobox.yml view on Meta::CPAN
---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: ComboBox
name: type
model_config:
options_from_model: 0
- type: Submit
name: submit
t/options_from_model/condition_from_stash_combobox.t view on Meta::CPAN
use strict;
use warnings;
use Test::More tests => 11;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/condition_from_stash_combobox.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $master_rs = $schema->resultset('Master');
my $user_rs = $schema->resultset('User');
{
my $m1 = $master_rs->create({ text_col => 'foo' });
t/options_from_model/condition_from_stash_combobox.t view on Meta::CPAN
ok( @$option == 5 );
is( $option->[0]->{label}, '' );
is( $option->[1]->{label}, 'd' );
is( $option->[2]->{label}, 'e' );
is( $option->[3]->{label}, 'f' );
is( $option->[4]->{label}, 'g' );
}
$form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/condition_from_stash_combobox.yml');
$form->stash->{schema} = $schema;
$form->stash->{master_id} = {'!=' => '2' };
$form->process;
{
my $option = $form->get_field('user')->options;
ok( @$option == 4 );
is( $option->[0]->{label}, '' );
t/options_from_model/condition_from_stash_combobox.yml view on Meta::CPAN
---
auto_fieldset: 1
elements:
- type: ComboBox
name: user
model_config:
resultset: User
condition_from_stash:
master: master_id
t/options_from_model/condition_from_stash_combobox_complex.t view on Meta::CPAN
use strict;
use warnings;
use Test::More tests => 5;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/condition_from_stash_combobox.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $master_rs = $schema->resultset('Master');
my $user_rs = $schema->resultset('User');
{
my $m1 = $master_rs->create({ text_col => 'foo' });
t/update/basic.yml view on Meta::CPAN
name: checkbox_col
value: foo
- type: Select
name: select_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: ComboBox
name: combobox_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: Radio
name: radio_col
value: yes
- type: Radio
t/update/basic_create.t view on Meta::CPAN
my $rs = $schema->resultset('Master');
# Fake submitted form
$form->process( {
id => 1,
text_col => 'a',
password_col => 'b',
checkbox_col => 'foo',
select_col => '2',
combobox_col_select => 'sel',
combobox_col_text => '',
radio_col => 'yes',
radiogroup_col => '3',
array_col => [qw(one two)],
} );
{
my $row = $rs->new( {} );
$form->model->update($row);
}
{
my $row = $rs->find(1);
is( $row->text_col, 'a' );
is( $row->password_col, 'b' );
is( $row->checkbox_col, 'foo' );
is( $row->select_col, '2' );
is( $row->combobox_col, 'sel' );
is( $row->radio_col, 'yes' );
is( $row->radiogroup_col, '3' );
is( ($row->array_col)->[0], 'one' );
is( ($row->array_col)->[1], 'two' );
}
$form->process( {
id => '',
text_col => 'a2',
password_col => 'b2',
t/update/basic_update.t view on Meta::CPAN
my $schema = new_schema();
my $rs = $schema->resultset('Master');
{
my $row = $rs->new_result( {
text_col => 'xyza',
password_col => 'xyzb',
checkbox_col => 'xyzfoo',
select_col => 'xyz2',
combobox_col => 'combo',
radio_col => 'xyzyes',
radiogroup_col => 'xyz3',
array_col => [qw(abc xyz)],
} );
$row->insert;
}
# Fake submitted form
$form->process( {
id => 1,
text_col => 'a',
password_col => 'b',
checkbox_col => 'foo',
select_col => '2',
combobox_col_select => '',
combobox_col_text => 'txt',
radio_col => 'yes',
radiogroup_col => '3',
array_col => [qw(one two)],
} );
{
my $row = $rs->find(1);
$form->model->update($row);
}
{
my $row = $rs->find(1);
is( $row->text_col, 'a' );
is( $row->password_col, 'b' );
is( $row->checkbox_col, 'foo' );
is( $row->combobox_col, 'txt' );
is( $row->select_col, '2' );
is( $row->radio_col, 'yes' );
is( $row->radiogroup_col, '3' );
is( ($row->array_col)->[0], 'one' );
is( ($row->array_col)->[1], 'two' );
}
t/update/belongs_to_combobox.t view on Meta::CPAN
use warnings;
use Test::More tests => 2;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/default_values/belongs_to_lookup_table_combobox.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $rs = $schema->resultset('Master');
# filler rows
{
# insert some entries we'll ignore, so our rels don't have same ids
t/update/belongs_to_lookup_table_combobox.t view on Meta::CPAN
use warnings;
use Test::More tests => 6;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/belongs_to_lookup_table_combobox.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $rs = $schema->resultset('Master');
# filler rows
{
# insert some entries we'll ignore, so our rels don't have same ids
t/update/belongs_to_lookup_table_combobox.t view on Meta::CPAN
$type_rs->delete;
$type_rs->create( { type => 'type 1' } );
$type_rs->create( { type => 'type 2' } );
$type_rs->create( { type => 'type 3' } );
}
# master 3
my $master = $rs->create( { text_col => 'aaa' } );
{
# submit combobox select ID
$form->process( {
"id" => 3,
"text_col" => 'bbb',
"type_select" => '2',
"type_text" => '',
} );
$form->model->update($master);
my $row = $rs->find(3);
is( $row->text_col, 'bbb');
is( $row->type->id, 2 );
is( $row->type->type, 'type 2' );
}
{
# submit combobox text field
# will create a new 'type' related row
$form->process( {
"id" => 3,
"text_col" => 'ccc',
"type_select" => '',
"type_text" => 'type 4',
} );
$form->model->update($master);
t/update/belongs_to_lookup_table_combobox.yml view on Meta::CPAN
---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: ComboBox
name: type
# set this, so options_from_model() populates the menu,
# so we can test the correct default is set
model_config:
resultset: Type
select_column: id
text_column: type
- type: Submit
name: submit
t/update/nested.yml view on Meta::CPAN
name: checkbox_col
value: foo
- type: Select
name: select_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: ComboBox
name: combobox_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: Radio
name: radio_col
value: yes
- type: Radio
t/update/nested_create.t view on Meta::CPAN
my $rs = $schema->resultset('Master');
# Fake submitted form
$form->process( {
"foo.id" => 1,
"foo.text_col" => 'a',
"foo.password_col" => 'b',
"foo.checkbox_col" => 'foo',
"foo.select_col" => '2',
"foo.combobox_col_select" => "",
"foo.combobox_col_text" => "combo",
"foo.radio_col" => 'yes',
"foo.radiogroup_col" => '3',
} );
{
my $row = $rs->new( {} );
$form->model->update( $row, { nested_base => 'foo' } );
}
{
my $row = $rs->find(1);
is( $row->text_col, 'a' );
is( $row->password_col, 'b' );
is( $row->checkbox_col, 'foo' );
is( $row->select_col, '2' );
is( $row->combobox_col, 'combo' );
is( $row->radio_col, 'yes' );
is( $row->radiogroup_col, '3' )
}