HTML-FormFu-Model-DBIC-2.03/ 0000775 0001751 0001752 00000000000 13262760616 013575 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/dist.ini 0000644 0001751 0001752 00000003537 13262760616 015247 0 ustar carl carl name = HTML-FormFu-Model-DBIC
author = Carl Franks
license = Perl_5
copyright_holder = Carl Franks
copyright_year = 2016
[Prereqs]
perl = 5.008001
DBD::SQLite = 0
DBIx::Class = 0.08108
HTML::FormFu = 2.00
List::MoreUtils = 0
MooseX::Attribute::Chained = 1.0.2
Storable = 0
Task::Weaken = 0 ; make sure Scalar::Util has weaken()
[Prereqs / TestRequires]
DateTime::Format::SQLite = 0
Locale::Maketext = 0
SQL::Translator = 0.11016 ; for $schema->deploy()
Test::More = 0.99
[Prereqs / DevelopRequires]
Test::Pod = 0
;; --
;; -- Sets of additional tests we want to do as part of release
[Test::Perl::Critic]
[MetaTests]
;; [PodCoverageTests] ; Currently we comprehensively fail these
[OurPkgVersion]
[PodVersion]
[Test::Kwalitee]
[Test::EOL]
finder = :InstallModules ; prevents test inputs being flagged
[Test::PAUSE::Permissions] ; if doing a release make sure we have PAUSE perms
;; -- Additional information
[GithubMeta] ; Grab the repo metadata
[NextRelease] ; Mark up the next release in changes
;; -- Additional git
[Git::GatherDir]
[Git::NextVersion] ; Get the next version tag from git
[Git::CheckFor::CorrectBranch] ; ensure on master branch for release
[Git::Remote::Check] ; ensure our branch is ahead of remote
;; -- We base the release stuff on the starter module, and tweak a bit
[@Starter]
-remove = GatherDir ; this is replaced by [Git::GatherDir]
ReadmeAnyFromPod.source_filename = lib/HTML/FormFu/Model/DBIC.pm
[ReadmeAnyFromPod / Pod_Readme]
type = pod
location = root ; do not include pod readmes in the build!
[@Git]
changelog = Changes
allow_dirty = dist.ini
allow_dirty = README.pod
allow_dirty = Changes
commit_msg = v%v%t - %d%n%n%c
tag_format = v%v%t ; see Git::Tag
tag_message = v%v%t - %d ; see Git::Tag HTML-FormFu-Model-DBIC-2.03/MANIFEST 0000644 0001751 0001752 00000016735 13262760616 014740 0 ustar carl carl # This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.011.
Changes
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
dist.ini
lib/HTML/FormFu/Constraint/DBIC/Unique.pm
lib/HTML/FormFu/Model/DBIC.pm
t/00-report-prereqs.dd
t/00-report-prereqs.t
t/constraints/dbic_unique.t
t/constraints/dbic_unique.yml
t/constraints/dbic_unique_column.yml
t/constraints/dbic_unique_id_field.yml
t/constraints/dbic_unique_method.yml
t/constraints/dbic_unique_others.yml
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/default_values/has_many_select.t
t/default_values/has_many_select.yml
t/default_values/has_one.t
t/default_values/has_one.yml
t/default_values/has_one_nested.t
t/default_values/has_one_nested.yml
t/default_values/label.t
t/default_values/label.yml
t/default_values/many_to_many-has_many.t
t/default_values/many_to_many-has_many.yml
t/default_values/many_to_many_checkboxgroup.t
t/default_values/many_to_many_checkboxgroup.yml
t/default_values/many_to_many_repeatable.t
t/default_values/many_to_many_repeatable.yml
t/default_values/many_to_many_repeatable_nested.t
t/default_values/many_to_many_repeatable_nested.yml
t/default_values/many_to_many_repeatable_new.t
t/default_values/many_to_many_repeatable_new.yml
t/default_values/many_to_many_select.t
t/default_values/many_to_many_select.yml
t/default_values/many_to_many_select_nested.t
t/default_values/many_to_many_select_nested.yml
t/default_values/methods.t
t/default_values/methods.yml
t/default_values/might_have.t
t/default_values/might_have.yml
t/default_values/might_have_missing.t
t/default_values/multi_label.t
t/default_values/multi_label.yml
t/default_values/nested_name_accessor.t
t/default_values/nested_name_accessor.yml
t/default_values/opt_accessor.t
t/default_values/opt_accessor.yml
t/default_values/opt_accessor_nested.t
t/default_values/opt_accessor_nested.yml
t/lib/DBICTestLib.pm
t/lib/HTMLFormFu/I18N.pm
t/lib/HTMLFormFu/I18N/en.pm
t/lib/HTMLFormFu/MockContext.pm
t/lib/MySchema.pm
t/lib/MySchema/Address.pm
t/lib/MySchema/Band.pm
t/lib/MySchema/HasMany.pm
t/lib/MySchema/ManagedBand.pm
t/lib/MySchema/Manager.pm
t/lib/MySchema/Master.pm
t/lib/MySchema/Note.pm
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
t/update/has_many_repeatable_many_new.yml
t/update/has_many_repeatable_many_new_exceed_max.t
t/update/has_many_repeatable_new.t
t/update/has_many_repeatable_new.yml
t/update/has_many_repeatable_new_date.t
t/update/has_many_repeatable_new_date.yml
t/update/has_many_repeatable_new_dependon.t
t/update/has_many_repeatable_new_dependon.yml
t/update/has_many_repeatable_new_empty.t
t/update/has_many_repeatable_new_implicit.t
t/update/has_many_repeatable_new_implicit.yml
t/update/has_many_repeatable_new_required_when.t
t/update/has_many_repeatable_new_required_when.yml
t/update/has_one.t
t/update/has_one.yml
t/update/has_one_create.t
t/update/has_one_no_id.t
t/update/has_one_no_id.yml
t/update/has_one_select.t
t/update/has_one_select.yml
t/update/ignore_if_empty.t
t/update/ignore_if_empty.yml
t/update/many_to_many-has_many.t
t/update/many_to_many_checkboxgroup.t
t/update/many_to_many_checkboxgroup.yml
t/update/many_to_many_checkboxgroup_read_only.t
t/update/many_to_many_checkboxgroup_read_only.yml
t/update/many_to_many_checkboxgroup_restricted.t
t/update/many_to_many_checkboxgroup_restricted.yml
t/update/many_to_many_checkboxgroup_unselected.t
t/update/many_to_many_repeatable.t
t/update/many_to_many_repeatable.yml
t/update/many_to_many_repeatable_new.t
t/update/many_to_many_repeatable_new.yml
t/update/many_to_many_select.t
t/update/many_to_many_select.yml
t/update/many_to_many_select_additive.yml
t/update/many_to_many_select_unselected.t
t/update/methods.t
t/update/methods.yml
t/update/might_have.t
t/update/might_have.yml
t/update/might_have_create.t
t/update/might_have_delete_if_empty.t
t/update/might_have_delete_if_empty.yml
t/update/nested.yml
t/update/nested_create.t
t/update/nested_create_checkbox.t
t/update/nested_name_accessor.t
t/update/nested_repeatable_write.t
t/update/nested_repeatable_write.yml
t/update/null_if_empty.t
t/update/null_if_empty.yml
t/update/opt_accessor.t
t/update/opt_accessor.yml
t/update/opt_accessor_nested.t
t/update/opt_accessor_nested.yml
t/update/unchecked_not_null_checkbox.t
t/x_roundtrip/checkbox.yml
t/x_roundtrip/checkbox_false2true.t
t/x_roundtrip/checkbox_true2false.t
xt/author/00-compile.t
xt/author/critic.t
xt/author/eol.t
xt/author/pod-syntax.t
xt/release/distmeta.t
xt/release/kwalitee.t
xt/release/pause-permissions.t
HTML-FormFu-Model-DBIC-2.03/t/ 0000775 0001751 0001752 00000000000 13262760616 014040 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/constraints/ 0000775 0001751 0001752 00000000000 13262760616 016407 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_repeatable_id_field.yml 0000644 0001751 0001752 00000000634 13262760616 025425 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: count
- type: Repeatable
nested_name: user
counter_name: count
model_config:
new_rows_max: 1
elements:
- type: Hidden
name: id
- name: name
constraints:
- type: DBIC::Unique
resultset: User
id_field: user.id
- name: title
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_method.yml 0000644 0001751 0001752 00000000477 13262760616 022767 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
constraints:
- Required
- type: DBIC::Unique
resultset: User
method_name: is_name_available
self_stash_key: user
- type: Text
name: title
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique.yml 0000644 0001751 0001752 00000000373 13262760616 021422 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
constraints:
- Required
- type: DBIC::Unique
resultset: User
- type: Text
name: title
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_repeatable_id_field.t 0000644 0001751 0001752 00000003272 13262760616 025070 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 8;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $schema = new_schema();
my $rs = $schema->resultset('User');
# Pre-existing rows
$rs->create( {
id => 1,
name => 'a',
title => 'b',
} );
$rs->create( {
id => 2,
name => 'e',
title => 'f',
} );
#
my $form = HTML::FormFu->new;
$form->load_config_file('t/constraints/dbic_unique_repeatable_id_field.yml');
$form->stash->{'schema'} = $schema;
# not valid
# try updating row#1 with the same name as row#2
# fails Unique
{
$form->process( {
'user_1.id' => 1,
'user_1.name' => 'e',
'user_1.title' => 'title',
} );
ok( !$form->submitted_and_valid );
ok( $form->has_errors('user_1.name') );
like( $form->get_field({ nested_name => 'user_1.name' }), qr/Value already exists/i );
}
# valid
# update row#1 with the same name it already has
{
$form->process( {
'user_1.id' => 1,
'user_1.name' => 'a',
'user_1.title' => 'title',
} );
ok( $form->submitted_and_valid );
}
# not valid
# try creating a new row with the same name as row#1
{
$form->process( {
'user_1.id' => '',
'user_1.name' => 'a',
'user_1.title' => 'title',
} );
ok( !$form->submitted_and_valid );
ok( $form->has_errors('user_1.name') );
like( $form->get_field({ nested_name => 'user_1.name' }), qr/Value already exists/i );
}
# valid
# create new row with a unique name
{
$form->process( {
'user_1.id' => '',
'user_1.name' => 'snowflake',
'user_1.title' => 'title',
} );
ok( $form->submitted_and_valid );
}
HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_others.yml 0000644 0001751 0001752 00000000424 13262760616 023003 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
constraints:
- Required
- type: DBIC::Unique
resultset: User
others: title
- type: Text
name: title
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique.t 0000644 0001751 0001752 00000010140 13262760616 021055 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 15;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $schema = new_schema();
my $rs = $schema->resultset('User');
# Pre-existing row to check against.
$rs->create( {
id => '1',
name => 'a',
title => 'b',
} );
# Second row to check against for method_name with record on stash
$rs->create( {
name => 'e',
title => 'f',
} );
# Basic form.
{
my $form = HTML::FormFu->new;
$form->load_config_file('t/constraints/dbic_unique.yml');
$form->stash->{'schema'} = $schema;
$form->process( {
'name' => 'a',
'title' => 'c',
} );
ok( !$form->submitted_and_valid );
is_deeply(
[
'name',
],
[ $form->has_errors ],
);
}
# Form where DB column differs from form field name.
{
my $form = HTML::FormFu->new;
$form->load_config_file('t/constraints/dbic_unique_column.yml');
$form->stash->{'schema'} = $schema;
$form->process( {
'username' => 'a',
'title' => 'c',
} );
ok( !$form->submitted_and_valid );
is_deeply(
[
'username',
],
[ $form->has_errors ],
);
}
# Form tracking a multi-column unique key (name+title).
{
my $form = HTML::FormFu->new;
$form->load_config_file('t/constraints/dbic_unique_others.yml');
$form->stash->{'schema'} = $schema;
$form->process( {
'name' => 'a',
'title' => 'c',
} );
ok( $form->submitted_and_valid );
$form->process( {
'name' => 'a',
'title' => 'b',
} );
ok( !$form->submitted_and_valid );
is_deeply(
[
'name',
],
[ $form->has_errors ],
);
}
# Form using a method_name to determine uniqueness with record on stash (is_name_available).
{
my $form = HTML::FormFu->new;
$form->load_config_file('t/constraints/dbic_unique_method.yml');
my $user = $schema->resultset('User')->find( {name => 'a'} );
$form->stash->{'schema'} = $schema;
$form->stash->{'user'} = $user;
$form->process( {
'name' => 'a',
'title' => 'b',
} );
ok( $form->submitted_and_valid );
$form->process( {
'name' => 'c',
'title' => 'd',
} );
ok( $form->submitted_and_valid );
$form->process( {
'name' => 'e',
'title' => 'f',
} );
}
# Form where id_field defined
{
my $form = HTML::FormFu->new;
$form->load_config_file('t/constraints/dbic_unique_id_field.yml');
$form->stash->{'schema'} = $schema;
# not uniq id - not uniq name => ok (no changes)
$form->process( {
'id' => '1',
'name' => 'a',
'title' => 'c',
} );
ok( $form->submitted_and_valid );
# no id - uniq name => ok
$form->process( {
'name' => 'c',
'title' => 'b',
} );
ok( $form->submitted_and_valid );
# not uniq id - uniq name => ok
$form->process( {
'id' => '1',
'name' => 'c',
'title' => 'b',
} );
ok( $form->submitted_and_valid );
# no id - not uniq name -> error
$form->process( {
'name' => 'a',
'title' => 'b',
} );
ok( !$form->submitted_and_valid );
# uniq id - not uniq name => error
$form->process( {
'id' => '2',
'name' => 'a',
'title' => 'b',
} );
ok( !$form->submitted_and_valid );
is_deeply(
[
'name',
],
[ $form->has_errors ],
);
}
HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_id_field.yml 0000644 0001751 0001752 00000000421 13262760616 023233 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
constraints:
- Required
- type: DBIC::Unique
resultset: User
id_field: id
- type: Text
name: title
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/constraints/dbic_unique_column.yml 0000644 0001751 0001752 00000000427 13262760616 022777 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: username
constraints:
- Required
- type: DBIC::Unique
resultset: User
column: name
- type: Text
name: title
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/x_roundtrip/ 0000775 0001751 0001752 00000000000 13262760616 016415 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/x_roundtrip/checkbox_false2true.t 0000644 0001751 0001752 00000002220 13262760616 022516 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 3;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $config_file = 't/x_roundtrip/checkbox.yml';
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler row
$rs->create( { text_col => 'filler', } );
# row we're going to use
# column value starts off false
$rs->create( {
checkbox_col => 0,
} );
# default_values()
{
my $form = HTML::FormFu->new;
$form->load_config_file( $config_file );
my $row = $rs->find(2);
$form->model->default_values($row);
# check field value
my $checkbox = $form->get_field('checkbox_col');
is( $checkbox->default, '0' );
my $expected_xhtml = q{};
like( "$checkbox", qr/\Q$expected_xhtml\E/ );
}
# update()
# value is submitted
{
my $form = HTML::FormFu->new;
$form->load_config_file( $config_file );
$form->process({
id => '2',
checkbox_col => '1',
});
my $row = $rs->find(2);
$form->model->update($row);
# check database
is( $row->checkbox_col, '1' );
}
HTML-FormFu-Model-DBIC-2.03/t/x_roundtrip/checkbox_true2false.t 0000644 0001751 0001752 00000002223 13262760616 022521 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 3;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $config_file = 't/x_roundtrip/checkbox.yml';
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler row
$rs->create( { text_col => 'filler', } );
# row we're going to use
# column value starts off true
$rs->create( {
checkbox_col => 1,
} );
# default_values()
{
my $form = HTML::FormFu->new;
$form->load_config_file( $config_file );
my $row = $rs->find(2);
$form->model->default_values($row);
# check field value
my $checkbox = $form->get_field('checkbox_col');
is( $checkbox->default, '1' );
my $expected_xhtml = q{};
like( "$checkbox", qr/\Q$expected_xhtml\E/ );
}
# update()
# value isn't submitted, so it becomes false
{
my $form = HTML::FormFu->new;
$form->load_config_file( $config_file );
$form->process({
id => 2,
});
my $row = $rs->find(2);
$form->model->update($row);
# check database
is( $row->checkbox_col, '0' );
}
HTML-FormFu-Model-DBIC-2.03/t/x_roundtrip/checkbox.yml 0000644 0001751 0001752 00000000114 13262760616 020720 0 ustar carl carl ---
elements:
- name: id
- type: Checkbox
name: checkbox_col
HTML-FormFu-Model-DBIC-2.03/t/00-report-prereqs.dd 0000644 0001751 0001752 00000004273 13262760616 017564 0 ustar carl carl do { my $x = {
'configure' => {
'requires' => {
'ExtUtils::MakeMaker' => '0'
}
},
'develop' => {
'requires' => {
'File::Spec' => '0',
'IO::Handle' => '0',
'IPC::Open3' => '0',
'Test::CPAN::Meta' => '0',
'Test::EOL' => '0',
'Test::Kwalitee' => '1.21',
'Test::More' => '0.88',
'Test::PAUSE::Permissions' => '0',
'Test::Perl::Critic' => '0',
'Test::Pod' => '1.41'
}
},
'runtime' => {
'requires' => {
'DBD::SQLite' => '0',
'DBIx::Class' => '0.08108',
'HTML::FormFu' => '2.00',
'List::MoreUtils' => '0',
'MooseX::Attribute::Chained' => 'v1.0.2',
'Storable' => '0',
'Task::Weaken' => '0',
'perl' => '5.008001'
}
},
'test' => {
'recommends' => {
'CPAN::Meta' => '2.120900'
},
'requires' => {
'DateTime::Format::SQLite' => '0',
'ExtUtils::MakeMaker' => '0',
'File::Spec' => '0',
'Locale::Maketext' => '0',
'SQL::Translator' => '0.11016',
'Test::More' => '0.99'
}
}
};
$x;
} HTML-FormFu-Model-DBIC-2.03/t/default_values/ 0000775 0001751 0001752 00000000000 13262760616 017043 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/default_values/might_have_missing.t 0000644 0001751 0001752 00000002307 13262760616 023074 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 4;
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/might_have.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
my $note_rs = $schema->resultset('Note');
{
# insert some entries we'll ignore, so our rels don't have same ids
# test id 1
my $t1 = $rs->new_result( { text_col => 'xxx' } );
$t1->insert;
# test id 2
my $t2 = $rs->new_result( { text_col => 'yyy' } );
$t2->insert;
# note id 1
my $n1 = $t2->new_related( 'note', { note => 'zzz' } );
$n1->insert;
# should get test id 3
my $master = $rs->new_result( { text_col => 'a', } );
$master->insert;
# no note
}
{
my $row = $rs->find(3);
$form->model->default_values($row);
is( $form->get_field('id')->render_data->{value}, 3 );
is( $form->get_field('text_col')->render_data->{value}, 'a' );
my $block = $form->get_all_element( { nested_name => 'note' } );
is( $block->get_field('id')->render_data->{value}, undef );
is( $block->get_field('note')->render_data->{value}, undef );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_label.yml 0000644 0001751 0001752 00000000572 13262760616 024712 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: address
model_config:
label: my_label
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/nested_name_accessor.yml 0000644 0001751 0001752 00000000146 13262760616 023731 0 ustar carl carl ---
elements:
- name: name
- type: Block
nested_name: foo
elements:
- name: value
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_one.yml 0000644 0001751 0001752 00000000337 13262760616 021203 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Block
nested_name: user
elements:
- type: Text
name: name
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/belongs_to_lookup_table.t 0000644 0001751 0001752 00000001174 13262760616 024124 0 ustar carl carl 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/default_values/belongs_to_lookup_table.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler row
$rs->create( { text_col => 'filler', } );
# row we're going to use
$rs->create( {
text_col => 'a',
type_id => 3,
} );
{
my $row = $rs->find(2);
$form->model->default_values($row);
is( $form->get_field('id')->default, 2 );
is( $form->get_field('type_id')->default, 3 );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_one_nested.yml 0000644 0001751 0001752 00000000362 13262760616 022543 0 ustar carl carl ---
auto_fieldset:
nested_name: foo
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Block
nested_name: user
elements:
- type: Text
name: name
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/opt_accessor.t 0000644 0001751 0001752 00000001422 13262760616 021711 0 ustar carl carl 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/default_values/opt_accessor.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler row
$master->create_related( 'user', { name => 'foo', } );
# row we're going to use
$master->create_related( 'user', {
title => 'mr',
name => 'billy bob',
} );
{
my $row = $schema->resultset('User')->find(2);
$form->model->default_values($row);
my $fs = $form->get_element;
is( $fs->get_field('id')->render_data->{value}, 2 );
is( $fs->get_field('fullname')->render_data->{value}, 'mr billy bob' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/methods.yml 0000644 0001751 0001752 00000000150 13262760616 021223 0 ustar carl carl ---
elements:
- type: Text
name: method_test
- type: Select
name: method_select_test HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable.t 0000644 0001751 0001752 00000002553 13262760616 023216 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 8;
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_repeatable.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
$master->create_related( 'user', {
name => 'filler',
addresses => [ { address => 'somewhere', } ] } );
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
# row we're going to use
$master->create_related( 'user', {
name => 'nick',
addresses => [ { address => 'home', }, { address => 'office', } ] } );
{
my $row = $schema->resultset('User')->find(4);
$form->model->default_values($row);
is( $form->get_field('id')->default, '4' );
is( $form->get_field('name')->default, 'nick' );
is( $form->get_field('count')->default, '2' );
my $block = $form->get_all_element( { nested_name => 'addresses' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 2 );
is( $reps[0]->get_field('id')->default, '2' );
is( $reps[0]->get_field('address')->default, 'home' );
is( $reps[1]->get_field('id')->default, '3' );
is( $reps[1]->get_field('address')->default, 'office' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_select.t 0000644 0001751 0001752 00000001775 13262760616 022376 0 ustar carl carl 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/default_values/has_many_select.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' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
# should get user id 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# should get address id 2
$u2->create_related( 'addresses', { address => 'home' } );
# should get address id 3
$u2->create_related( 'addresses', { address => 'office' } );
}
{
my $row = $schema->resultset('User')->find(2);
$form->model->default_values($row);
is_deeply( $form->get_field('addresses')->default, [ 2, 3 ] );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/opt_accessor_nested.yml 0000644 0001751 0001752 00000000302 13262760616 023605 0 ustar carl carl ---
auto_fieldset:
nested_name: foo
elements:
- type: Hidden
name: id
- type: Text
name: fullname
model_config:
accessor: fullname
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/opt_accessor.yml 0000644 0001751 0001752 00000000257 13262760616 022254 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: fullname
model_config:
accessor: fullname
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/basic_nested.yml 0000644 0001751 0001752 00000001132 13262760616 022204 0 ustar carl carl ---
auto_fieldset:
nested_name: foo
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Password
name: password_col
- type: Checkbox
name: checkbox_col
value: foo
- type: Select
name: select_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: Radio
name: radio_col
value: yes
- type: Radio
name: radio_col
value: no
- type: Radiogroup
name: radiogroup_col
values: [1, 2, 3]
- type: Text
name: date_col
- type: Text
name: unknown_col
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable_nested.yml 0000644 0001751 0001752 00000000526 13262760616 026007 0 ustar carl carl ---
auto_fieldset:
nested_name: foo
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: bands
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: band
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable_new.yml 0000644 0001751 0001752 00000000551 13262760616 025314 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: bands
counter_name: count
model_config:
empty_rows: 1
elements:
- type: Hidden
name: id
- type: Text
name: band
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_select_nested.t 0000644 0001751 0001752 00000002115 13262760616 024620 0 ustar carl carl use strict;
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/many_to_many_select_nested.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
{
$master->create_related( 'user', { name => 'John', } );
$master->create_related( 'user', { name => 'Ringo', } );
my $user3 = $master->create_related( 'user', { name => 'George', } );
$user3->add_to_bands( { band => 'the kinks', } );
}
# row we're going to use
{
my $paul = $master->create_related( 'user', { name => 'Paul', } );
$paul->add_to_bands( { band => 'the beatles', } );
$paul->add_to_bands( { band => 'wings', } );
}
{
my $row = $schema->resultset('User')->find(4);
$form->model->default_values( $row, { nested_base => 'foo' } );
is( $form->get_field('id')->default, 4 );
is( $form->get_field('name')->default, 'Paul' );
is_deeply( $form->get_field('bands')->default, [ 2, 3 ] );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_select_nested.yml 0000644 0001751 0001752 00000000305 13262760616 025155 0 ustar carl carl ---
auto_fieldset:
nested_name: foo
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Select
name: bands
multiple: 1
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_select.yml 0000644 0001751 0001752 00000000310 13262760616 022714 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Select
name: addresses
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable.yml 0000644 0001751 0001752 00000000512 13262760616 023545 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable_new.t 0000644 0001751 0001752 00000003304 13262760616 024755 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 12;
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/many_to_many_repeatable_new.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
{
my $user = $master->create_related( 'user', { name => 'filler', } );
$user->add_to_bands( { band => 'a', } );
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
$master->create_related( 'user', { name => 'filler4', } );
}
# row we're going to use
{
my $user = $master->create_related( 'user', { name => 'nick', } );
$user->add_to_bands( { band => 'b', } );
$user->add_to_bands( { band => 'c', } );
$user->add_to_bands( { band => 'd', } );
}
{
my $row = $schema->resultset('User')->find(5);
$form->model->default_values($row);
is( $form->get_field('id')->default, '5' );
is( $form->get_field('name')->default, 'nick' );
is( $form->get_field('count')->default, '4' );
my $block = $form->get_all_element( { nested_name => 'bands' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 4 );
is( $reps[0]->get_field('id')->default, '2' );
is( $reps[0]->get_field('band')->default, 'b' );
is( $reps[1]->get_field('id')->default, '3' );
is( $reps[1]->get_field('band')->default, 'c' );
is( $reps[2]->get_field('id')->default, '4' );
is( $reps[2]->get_field('band')->default, 'd' );
is( $reps[3]->get_field('id')->default, undef );
is( $reps[3]->get_field('band')->default, undef );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/multi_label.t 0000644 0001751 0001752 00000001454 13262760616 021523 0 ustar carl carl 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/default_values/multi_label.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler row
$master->create_related( 'user', { name => 'foo', } );
# row we're going to use
$master->create_related( 'user', {
title => 'mr',
name => 'billy bob',
} );
{
my $row = $schema->resultset('User')->find(2);
$form->model->default_values($row);
my $multi = $form->get_element({ type => 'Multi' });
is( $multi->render_data->{label}, 'mr' );
my $name = $multi->get_field('name')->render_data;
is( $name->{value}, 'billy bob' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/opt_accessor_nested.t 0000644 0001751 0001752 00000001544 13262760616 023260 0 ustar carl carl 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/default_values/opt_accessor_nested.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler row
$master->create_related( 'user', { name => 'foo', } );
# row we're going to use
$master->create_related( 'user', {
title => 'mr',
name => 'billy bob',
} );
{
my $row = $schema->resultset('User')->find(2);
$form->model->default_values( $row, { nested_base => 'foo' } );
is( $form->get_field( { nested_name => 'foo.id' } )->render_data->{value},
2 );
is( $form->get_field( { nested_name => 'foo.fullname' } )
->render_data->{value},
'mr billy bob'
);
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_delete_true.t 0000644 0001751 0001752 00000003435 13262760616 025577 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 18;
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_repeatable_delete_true.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# row we're going to use
$master->create_related( 'user', {
name => 'nick',
addresses => [ { address => 'home', }, { address => 'office', } ] } );
{
my $row = $schema->resultset('User')->find(1);
$form->model->default_values($row);
is( $form->get_field('id')->default, '1' );
is( $form->get_field('name')->default, 'nick' );
is( $form->get_field('count')->default, '4' );
my $block = $form->get_all_element( { nested_name => 'addresses' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 4 );
is( $reps[0]->nested_name, 'addresses_1' );
is( $reps[0]->get_field('id')->default, '1' );
is( $reps[0]->get_field('address')->default, 'home' );
ok( $reps[0]->get_field({ type => 'Checkbox' }) );
is( $reps[1]->nested_name, 'addresses_2' );
is( $reps[1]->get_field('id')->default, '2' );
is( $reps[1]->get_field('address')->default, 'office' );
ok( $reps[1]->get_field({ type => 'Checkbox' }) );
# empty rows
is( $reps[2]->get_field('id')->default, undef );
is( $reps[2]->get_field('address')->default, undef );
# checkbox has been removed
ok( !$reps[2]->get_field({ type => 'Checkbox' }) );
is( $reps[3]->get_field('id')->default, undef );
is( $reps[3]->get_field('address')->default, undef );
# checkbox has been removed
ok( !$reps[3]->get_field({ type => 'Checkbox' }) );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_delete_true.yml 0000644 0001751 0001752 00000000717 13262760616 026135 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
model_config:
empty_rows: 2
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Checkbox
name: delete
model_config:
delete_if_true: 1
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_nested.t 0000644 0001751 0001752 00000003676 13262760616 024567 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 12;
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_repeatable_nested.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
$master->create_related( 'user', {
name => 'filler',
addresses => [ { address => 'somewhere', } ] } );
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
# row we're going to use
$master->create_related( 'user', {
name => 'nick',
addresses => [ { address => 'home', }, { address => 'office', } ] } );
{
my $row = $schema->resultset('User')->find(4);
$form->model->default_values( $row, { nested_base => 'foo' } );
is( $form->get_field( { nested_name => 'foo.id' } )->default, '4' );
is( $form->get_field( { nested_name => 'foo.name' } )->default, 'nick' );
is( $form->get_field( { nested_name => 'foo.count' } )->default, '2' );
my $block = $form->get_all_element( { nested_name => 'addresses' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 2 );
is( $reps[0]->get_field('id')->default, '2' );
is( $reps[0]->get_field('address')->default, 'home' );
is( $reps[1]->get_field('id')->default, '3' );
is( $reps[1]->get_field('address')->default, 'office' );
# check the same values from the form, not the block
is( $form->get_field( { nested_name => 'foo.addresses_1.id' } )->default,
'2' );
is( $form->get_field( { nested_name => 'foo.addresses_1.address' } )
->default,
'home'
);
is( $form->get_field( { nested_name => 'foo.addresses_2.id' } )->default,
'3' );
is( $form->get_field( { nested_name => 'foo.addresses_2.address' } )
->default,
'office'
);
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/might_have.t 0000644 0001751 0001752 00000002445 13262760616 021346 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 4;
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/might_have.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
my $note_rs = $schema->resultset('Note');
{
# insert some entries we'll ignore, so our rels don't have same ids
# test id 1
my $t1 = $rs->new_result( { text_col => 'xxx' } );
$t1->insert;
# test id 2
my $t2 = $rs->new_result( { text_col => 'yyy' } );
$t2->insert;
# note id 1
my $n1 = $t2->new_related( 'note', { note => 'zzz' } );
$n1->insert;
# should get test id 3
my $master = $rs->new_result( { text_col => 'a', } );
$master->insert;
# should get note id 2
my $note = $master->new_related( 'note', { note => 'abc' } );
$note->insert;
}
{
my $row = $rs->find(3);
$form->model->default_values($row);
is( $form->get_field('id')->render_data->{value}, 3 );
is( $form->get_field('text_col')->render_data->{value}, 'a' );
my $block = $form->get_all_element( { nested_name => 'note' } );
is( $block->get_field('id')->render_data->{value}, 2 );
is( $block->get_field('note')->render_data->{value}, 'abc' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_one.t 0000644 0001751 0001752 00000002265 13262760616 020647 0 ustar carl carl use strict;
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/has_one.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
{
# insert some entries we'll ignore, so our rels don't have same ids
# test id 1
my $t1 = $rs->new_result( { text_col => 'xxx' } );
$t1->insert;
# test id 2
my $t2 = $rs->new_result( { text_col => 'yyy' } );
$t2->insert;
# user id 1
my $n1 = $t2->new_related( 'user', { name => 'foo' } );
$n1->insert;
# should get test id 3
my $master = $rs->new_result( { text_col => 'a', } );
$master->insert;
# should get note id 2
my $user = $master->new_related( 'user', { name => 'bar' } );
$user->insert;
}
{
my $row = $rs->find(3);
$form->model->default_values($row);
is( $form->get_field('id')->render_data->{value}, 3 );
is( $form->get_field('text_col')->render_data->{value}, 'a' );
my $block = $form->get_all_element( { nested_name => 'user' } );
is( $block->get_field('name')->render_data->{value}, 'bar' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/belongs_to_lookup_table.yml 0000644 0001751 0001752 00000000315 13262760616 024456 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Select
name: type_id
- type: Select
name: type2_id
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable.yml 0000644 0001751 0001752 00000000503 13262760616 024440 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: bands
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: band
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/empty_rows_zero.yml 0000644 0001751 0001752 00000000521 13262760616 023031 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Repeatable
nested_name: addresses
counter_name: count
model_config:
empty_rows: 0
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_select.yml 0000644 0001751 0001752 00000000262 13262760616 023615 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Select
name: bands
multiple: 1
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many-has_many.yml 0000644 0001751 0001752 00000000765 13262760616 024063 0 ustar carl carl ---
auto_fieldset: 1
elements:
- name: band
- type: Hidden
name: count
- type: Repeatable
nested_name: users
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Hidden
name: count
- type: Repeatable
nested_name: addresses
counter_name: count
elements:
- type: Hidden
name: id
- name: address
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_new.t 0000644 0001751 0001752 00000003131 13262760616 024060 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 12;
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_repeatable_new.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
$master->create_related( 'user', {
name => 'filler',
addresses => [ { address => 'somewhere', } ] } );
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
# row we're going to use
$master->create_related( 'user', {
name => 'nick',
addresses => [ { address => 'home', }, { address => 'office', } ] } );
{
my $row = $schema->resultset('User')->find(4);
$form->model->default_values($row);
is( $form->get_field('id')->default, '4' );
is( $form->get_field('name')->default, 'nick' );
is( $form->get_field('count')->default, '4' );
my $block = $form->get_all_element( { nested_name => 'addresses' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 4 );
is( $reps[0]->get_field('id')->default, '2' );
is( $reps[0]->get_field('address')->default, 'home' );
is( $reps[1]->get_field('id')->default, '3' );
is( $reps[1]->get_field('address')->default, 'office' );
is( $reps[2]->get_field('id')->default, undef );
is( $reps[2]->get_field('address')->default, undef );
is( $reps[3]->get_field('id')->default, undef );
is( $reps[3]->get_field('address')->default, undef );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_checkboxgroup.yml 0000644 0001751 0001752 00000000251 13262760616 025177 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Checkboxgroup
name: bands
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/might_have.yml 0000644 0001751 0001752 00000000412 13262760616 021674 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Block
nested_name: note
elements:
- type: Hidden
name: id
- type: Textarea
name: note
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable.t 0000644 0001751 0001752 00000003120 13262760616 024100 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 10;
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/many_to_many_repeatable.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
{
my $user = $master->create_related( 'user', { name => 'filler', } );
$user->add_to_bands( { band => 'a', } );
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
$master->create_related( 'user', { name => 'filler4', } );
}
# row we're going to use
{
my $user = $master->create_related( 'user', { name => 'nick', } );
$user->add_to_bands( { band => 'b', } );
$user->add_to_bands( { band => 'c', } );
$user->add_to_bands( { band => 'd', } );
}
{
my $row = $schema->resultset('User')->find(5);
$form->model->default_values($row);
is( $form->get_field('id')->default, '5' );
is( $form->get_field('name')->default, 'nick' );
is( $form->get_field('count')->default, '3' );
my $block = $form->get_all_element( { nested_name => 'bands' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 3 );
is( $reps[0]->get_field('id')->default, '2' );
is( $reps[0]->get_field('band')->default, 'b' );
is( $reps[1]->get_field('id')->default, '3' );
is( $reps[1]->get_field('band')->default, 'c' );
is( $reps[2]->get_field('id')->default, '4' );
is( $reps[2]->get_field('band')->default, 'd' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/empty_rows_zero.t 0000644 0001751 0001752 00000001773 13262760616 022505 0 ustar carl carl use strict;
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/empty_rows_zero.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
$master->create_related( 'user', {
name => 'filler',
addresses => [ { address => 'somewhere', } ] } );
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
# row we're going to use
$master->create_related( 'user', {
name => 'nick' } );
{
my $row = $schema->resultset('User')->find(4);
$form->model->default_values($row);
is( $form->get_field('id')->default, '4' );
is( $form->get_field('count')->default, '0' );
my $block = $form->get_all_element( { nested_name => 'addresses' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 0 );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_checkboxgroup.t 0000644 0001751 0001752 00000002061 13262760616 024642 0 ustar carl carl use strict;
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/many_to_many_checkboxgroup.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
{
$master->create_related( 'user', { name => 'John', } );
$master->create_related( 'user', { name => 'Ringo', } );
my $user3 = $master->create_related( 'user', { name => 'George', } );
$user3->add_to_bands( { band => 'the kinks', } );
}
# row we're going to use
{
my $paul = $master->create_related( 'user', { name => 'Paul', } );
$paul->add_to_bands( { band => 'the beatles', } );
$paul->add_to_bands( { band => 'wings', } );
}
{
my $row = $schema->resultset('User')->find(4);
$form->model->default_values($row);
is( $form->get_field('id')->default, 4 );
is( $form->get_field('name')->default, 'Paul' );
is_deeply( $form->get_field('bands')->default, [ 2, 3 ] );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_combobox.yml 0000644 0001751 0001752 00000000312 13262760616 023247 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: ComboBox
name: addresses
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_repeatable_nested.t 0000644 0001751 0001752 00000004404 13262760616 025450 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 16;
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/many_to_many_repeatable_nested.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
{
my $user = $master->create_related( 'user', { name => 'filler', } );
$user->add_to_bands( { band => 'a', } );
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
$master->create_related( 'user', { name => 'filler4', } );
}
# row we're going to use
{
my $user = $master->create_related( 'user', { name => 'nick', } );
$user->add_to_bands( { band => 'b', } );
$user->add_to_bands( { band => 'c', } );
$user->add_to_bands( { band => 'd', } );
}
{
my $row = $schema->resultset('User')->find(5);
$form->model->default_values( $row, { nested_base => 'foo' } );
is( $form->get_field( { nested_name => 'foo.id' } )->default, '5' );
is( $form->get_field( { nested_name => 'foo.name' } )->default, 'nick' );
is( $form->get_field( { nested_name => 'foo.count' } )->default, '3' );
my $block = $form->get_all_element( { nested_name => 'bands' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 3 );
is( $reps[0]->get_field('id')->default, '2' );
is( $reps[0]->get_field('band')->default, 'b' );
is( $reps[1]->get_field('id')->default, '3' );
is( $reps[1]->get_field('band')->default, 'c' );
is( $reps[2]->get_field('id')->default, '4' );
is( $reps[2]->get_field('band')->default, 'd' );
# check the same values from the form, not the block
is( $form->get_field( { nested_name => 'foo.bands_1.id' } )->default, '2' );
is( $form->get_field( { nested_name => 'foo.bands_1.band' } )->default,
'b' );
is( $form->get_field( { nested_name => 'foo.bands_2.id' } )->default, '3' );
is( $form->get_field( { nested_name => 'foo.bands_2.band' } )->default,
'c' );
is( $form->get_field( { nested_name => 'foo.bands_3.id' } )->default, '4' );
is( $form->get_field( { nested_name => 'foo.bands_3.band' } )->default,
'd' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/basic.yml 0000644 0001751 0001752 00000001255 13262760616 020650 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Password
name: password_col
- type: Checkbox
name: checkbox_col
value: foo
- type: Select
name: select_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: Radio
name: radio_col
value: yes
- type: Radio
name: radio_col
value: no
- type: Radiogroup
name: radiogroup_col
values: [1, 2, 3]
- type: Checkboxgroup
name: array_col
options:
- [one]
- [two]
- [three]
- type: Date
name: date_col
- type: Text
name: unknown_col
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/nested_name_accessor.t 0000644 0001751 0001752 00000001526 13262760616 023376 0 ustar carl carl 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/default_values/nested_name_accessor.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler row
$master->create_related( 'user', { name => 'filler', } );
# row we're going to use
my $row = $master->create_related( 'user', {
name => 'mr. foo',
} );
$row->create_related( 'hasmanys', { key => 'bar', value => 'a' } );
$row->create_related( 'hasmanys', { key => 'foo', value => 'b' } );
{
my $row = $schema->resultset('User')->find(2);
$form->model->default_values($row);
is( $form->get_field('name')->default, 'mr. foo' );
is ( $form->get_field('value')->default, 'b' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/methods.t 0000644 0001751 0001752 00000001030 13262760616 020663 0 ustar carl carl 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/default_values/methods.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler row
$rs->create( { text_col => 'filler', } );
{
my $row = $rs->find(1);
$form->model->default_values($row);
my $field = $form->get_element('method_test');
is( $field->render_data->{value}, "filler" );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_nested.yml 0000644 0001751 0001752 00000000535 13262760616 025114 0 ustar carl carl ---
auto_fieldset:
nested_name: foo
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/belongs_to_lookup_table_combobox.yml 0000644 0001751 0001752 00000000630 13262760616 026346 0 ustar carl carl ---
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
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many_select.t 0000644 0001751 0001752 00000002052 13262760616 023256 0 ustar carl carl use strict;
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/many_to_many_select.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
{
$master->create_related( 'user', { name => 'John', } );
$master->create_related( 'user', { name => 'Ringo', } );
my $user3 = $master->create_related( 'user', { name => 'George', } );
$user3->add_to_bands( { band => 'the kinks', } );
}
# row we're going to use
{
my $paul = $master->create_related( 'user', { name => 'Paul', } );
$paul->add_to_bands( { band => 'the beatles', } );
$paul->add_to_bands( { band => 'wings', } );
}
{
my $row = $schema->resultset('User')->find(4);
$form->model->default_values($row);
is( $form->get_field('id')->default, 4 );
is( $form->get_field('name')->default, 'Paul' );
is_deeply( $form->get_field('bands')->default, [ 2, 3 ] );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/many_to_many-has_many.t 0000644 0001751 0001752 00000006356 13262760616 023527 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 22;
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/many_to_many-has_many.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $user = $master->create_related( 'user', { name => 'filler', } );
# band 1
$user->add_to_bands( { band => 'a', } );
# address 1
$user->add_to_addresses( { address => 'b' } );
# user 2,3,4
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
$master->create_related( 'user', { name => 'filler4', } );
}
# rows we're going to use
{
# band 2
my $band = $schema->resultset('Band')->create({ band => 'band 2' });
# user 5,6
my $user1 = $band->add_to_users({ name => 'user 5', master => $master->id });
my $user2 = $band->add_to_users({ name => 'user 6', master => $master->id });
# address 2,3
$user1->create_related( 'addresses', { address => 'add 2' } );
$user1->create_related( 'addresses', { address => 'add 3' } );
# address 4
$user2->create_related( 'addresses', { address => 'add 4' } );
}
{
my $row = $schema->resultset('Band')->find(2);
$form->model->default_values($row);
is( $form->get_field('band')->default, 'band 2' );
is( $form->get_field('count')->default, '2' );
my $user_repeatable = $form->get_all_element( { nested_name => 'users' } );
my @users = @{ $user_repeatable->get_elements };
is( scalar @users, 2 );
# user 5
{
is( $users[0]->nested_name, 'users_1' );
is( $users[0]->get_field('id')->default, '5' );
is( $users[0]->get_field('name')->default, 'user 5' );
is( $users[0]->get_field('count')->default, '2' );
my $addresses_repeatable = $users[0]->get_all_element({ nested_name => 'addresses' });
my @addresses = @{ $addresses_repeatable->get_elements };
is( scalar @addresses, 2 );
# address 2
is( $addresses[0]->nested_name, 'addresses_1' );
is( $addresses[0]->get_field('id')->default, '2' );
is( $addresses[0]->get_field('address')->default, 'add 2' );
# address 3
is( $addresses[1]->nested_name, 'addresses_2' );
is( $addresses[1]->get_field('id')->default, '3' );
is( $addresses[1]->get_field('address')->default, 'add 3' );
}
# user 6
{
is( $users[1]->nested_name, 'users_2' );
is( $users[1]->get_field('id')->default, '6' );
is( $users[1]->get_field('name')->default, 'user 6' );
is( $users[1]->get_field('count')->default, '1' );
my $addresses_repeatable = $users[1]->get_all_element({ nested_name => 'addresses' });
my @addresses = @{ $addresses_repeatable->get_elements };
is( scalar @addresses, 1 );
# address 4
is( $addresses[0]->nested_name, 'addresses_1' );
is( $addresses[0]->get_field('id')->default, '4' );
is( $addresses[0]->get_field('address')->default, 'add 4' );
}
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/basic_nested.t 0000644 0001751 0001752 00000005350 13262760616 021654 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 25;
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/basic_nested.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler row
$rs->create( { text_col => 'filler', } );
# row we're going to use
$rs->create( {
text_col => 'a',
password_col => 'b',
checkbox_col => 'foo',
select_col => '2',
radio_col => 'yes',
radiogroup_col => '3',
date_col => '2006-12-31 00:00:00'
} );
{
my $row = $rs->find(2);
$form->model->default_values( $row, { nested_base => 'foo' } );
my $fs = $form->get_element;
is( $fs->get_field( { nested_name => 'foo.id' } )->render_data->{value},
2 );
is( $fs->get_field( { nested_name => 'foo.text_col' } )
->render_data->{value},
'a'
);
is( $fs->get_field( { nested_name => 'foo.password_col' } )
->render_data->{value},
undef
);
my $checkbox
= $fs->get_field( { nested_name => 'foo.checkbox_col' } )->render_data;
is( $checkbox->{value}, 'foo' );
is( $checkbox->{attributes}{checked}, 'checked' );
# accessing undocumented HTML::FormFu internals below
# may break in the future
my $select
= $fs->get_field( { nested_name => 'foo.select_col' } )->render_data;
is( $select->{options}[0]{value}, 1 );
ok( !exists $select->{options}[0]{attributes}{selected} );
is( $select->{options}[1]{value}, 2 );
is( $select->{options}[1]{attributes}{selected}, 'selected' );
is( $select->{options}[2]{value}, 3 );
ok( !exists $select->{options}[2]{attributes}{selected} );
my @radio = map { $_->render_data }
@{ $form->get_fields( { nested_name => 'foo.radio_col' } ) };
is( $radio[0]->{value}, 'yes' );
is( $radio[0]->{attributes}{checked}, 'checked' );
is( $radio[1]->{value}, 'no' );
ok( !exists $radio[1]->{attributes}{checked} );
my @rg_option = @{ $fs->get_field( { nested_name => 'foo.radiogroup_col' } )
->render_data->{options} };
is( $rg_option[0]->{value}, 1 );
ok( !exists $rg_option[0]->{attributes}{checked} );
is( $rg_option[1]->{value}, 2 );
ok( !exists $rg_option[1]->{attributes}{checked} );
is( $rg_option[2]->{value}, 3 );
is( $rg_option[2]->{attributes}{checked}, 'checked' );
# column is inflated
my $date = $fs->get_field( { nested_name => 'foo.date_col' } )->default;
isa_ok( $date, 'DateTime' );
is( $date->day, '31' );
is( $date->month, '12' );
is( $date->year, '2006' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_combobox.t 0000644 0001751 0001752 00000001776 13262760616 022730 0 ustar carl carl 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/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' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
# should get user id 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# should get address id 2
$u2->create_related( 'addresses', { address => 'home' } );
# should get address id 3
$u2->create_related( 'addresses', { address => 'office' } );
}
{
my $row = $schema->resultset('User')->find(2);
$form->model->default_values($row);
is_deeply( $form->get_field('addresses')->default, [ 2, 3 ] );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/multi_label.yml 0000644 0001751 0001752 00000000314 13262760616 022053 0 ustar carl carl ---
elements:
- type: Multi
model_config:
label: title
elements:
- type: Hidden
name: id
- type: Text
name: name
- type : Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_new.yml 0000644 0001751 0001752 00000000560 13262760616 024421 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
model_config:
empty_rows: 2
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/label.t 0000644 0001751 0001752 00000001374 13262760616 020312 0 ustar carl carl 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/default_values/label.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler row
$master->create_related( 'user', { name => 'foo', } );
# row we're going to use
$master->create_related( 'user', {
title => 'mr',
name => 'billy bob',
} );
{
my $row = $schema->resultset('User')->find(2);
$form->model->default_values($row);
my $fs = $form->get_element;
my $name = $fs->get_field('name')->render_data;
is( $name->{value}, 'billy bob' );
is( $name->{label}, 'mr' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/belongs_to_lookup_table_combobox.t 0000644 0001751 0001752 00000002102 13262760616 026004 0 ustar carl carl use strict;
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');
# types
$type_rs->delete;
$type_rs->create( { type => 'type 1' } );
$type_rs->create( { type => 'type 2' } );
$type_rs->create( { type => 'type 3' } );
}
# filler row
$rs->create( { text_col => 'filler', } );
# row we're going to use
$rs->create( {
text_col => 'a',
type_id => 3,
} );
{
my $row = $rs->find(2);
$form->process;
$form->model->default_values($row);
is( $form->get_field('id')->default, 2 );
my $type_field = $form->get_field('type');
is( $type_field->default, 3 );
# test correct select option is selected
like( "$type_field", qr{} );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/label.yml 0000644 0001751 0001752 00000000245 13262760616 020644 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
model_config:
label: title
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_one_nested.t 0000644 0001751 0001752 00000002534 13262760616 022210 0 ustar carl carl use strict;
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/has_one_nested.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
{
# insert some entries we'll ignore, so our rels don't have same ids
# test id 1
my $t1 = $rs->new_result( { text_col => 'xxx' } );
$t1->insert;
# test id 2
my $t2 = $rs->new_result( { text_col => 'yyy' } );
$t2->insert;
# user id 1
my $n1 = $t2->new_related( 'user', { name => 'foo' } );
$n1->insert;
# should get test id 3
my $master = $rs->new_result( { text_col => 'a', } );
$master->insert;
# should get note id 2
my $user = $master->new_related( 'user', { name => 'bar' } );
$user->insert;
}
{
my $row = $rs->find(3);
$form->model->default_values( $row, { nested_base => 'foo' } );
is( $form->get_field( { nested_name => 'foo.id' } )->render_data->{value},
3 );
is( $form->get_field( { nested_name => 'foo.text_col' } )
->render_data->{value},
'a'
);
my $block = $form->get_all_element( { nested_name => 'user' } );
is( $block->get_field( { nested_name => 'foo.user.name' } )
->render_data->{value},
'bar'
);
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/basic.t 0000644 0001751 0001752 00000006004 13262760616 020307 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 31;
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/basic.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler row
$rs->create( { text_col => 'filler', } );
# row we're going to use
$rs->create( {
text_col => 'a',
password_col => 'b',
checkbox_col => 'foo',
select_col => '2',
radio_col => 'yes',
radiogroup_col => '3',
array_col => [qw(one two)],
date_col => '2006-12-31 00:00:00'
} );
{
my $row = $rs->find(2);
$form->model->default_values($row);
my $fs = $form->get_element;
is( $fs->get_field('id')->render_data->{value}, 2 );
is( $fs->get_field('text_col')->render_data->{value}, 'a' );
is( $fs->get_field('password_col')->render_data->{value}, undef );
my $checkbox = $fs->get_field('checkbox_col')->render_data;
is( $checkbox->{value}, 'foo' );
is( $checkbox->{attributes}{checked}, 'checked' );
# accessing undocumented HTML::FormFu internals below
# may break in the future
my $select = $fs->get_field('select_col')->render_data;
is( $select->{options}[0]{value}, 1 );
ok( !exists $select->{options}[0]{attributes}{selected} );
is( $select->{options}[1]{value}, 2 );
is( $select->{options}[1]{attributes}{selected}, 'selected' );
is( $select->{options}[2]{value}, 3 );
ok( !exists $select->{options}[2]{attributes}{selected} );
my @radio = map { $_->render_data } @{ $form->get_fields('radio_col') };
is( $radio[0]->{value}, 'yes' );
is( $radio[0]->{attributes}{checked}, 'checked' );
is( $radio[1]->{value}, 'no' );
ok( !exists $radio[1]->{attributes}{checked} );
my @rg_option
= @{ $fs->get_field('radiogroup_col')->render_data->{options} };
is( $rg_option[0]->{value}, 1 );
ok( !exists $rg_option[0]->{attributes}{checked} );
is( $rg_option[1]->{value}, 2 );
ok( !exists $rg_option[1]->{attributes}{checked} );
is( $rg_option[2]->{value}, 3 );
is( $rg_option[2]->{attributes}{checked}, 'checked' );
# column is inflated
# my $ary_col = $fs->get_field('array_col')->default;
# isa_ok( $ary_col, 'ARRAY' );
my $ary_col = $fs->get_field('array_col')->render_data;
is( $ary_col->{options}[0]{value}, 'one' );
is( $ary_col->{options}[0]{attributes}{checked}, 'checked' );
is( $ary_col->{options}[1]{value}, 'two' );
is( $ary_col->{options}[1]{attributes}{checked}, 'checked' );
is( $ary_col->{options}[2]{value}, 'three' );
ok( !exists $ary_col->{options}[2]{attributes}{checked} );
# column is inflated
my $date = $fs->get_field('date_col')->default;
isa_ok( $date, 'DateTime' );
is( $date->day, '31' );
is( $date->month, '12' );
is( $date->year, '2006' );
}
HTML-FormFu-Model-DBIC-2.03/t/default_values/has_many_repeatable_label.t 0000644 0001751 0001752 00000003077 13262760616 024357 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 10;
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_repeatable_label.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler
$master->create_related( 'user', {
name => 'filler',
addresses => [ { address => 'somewhere', } ] } );
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
# row we're going to use
$master->create_related( 'user', {
name => 'nick',
addresses => [
{ address => 'home', my_label => 'label 1' },
{ address => 'office', my_label => 'label 2' },
] } );
{
my $row = $schema->resultset('User')->find(4);
$form->model->default_values($row);
is( $form->get_field('id')->default, '4' );
is( $form->get_field('name')->default, 'nick' );
is( $form->get_field('count')->default, '2' );
my $block = $form->get_all_element( { nested_name => 'addresses' } );
my @reps = @{ $block->get_elements };
is( scalar @reps, 2 );
is( $reps[0]->get_field('id')->default, '2' );
is( $reps[0]->get_field('address')->default, 'home' );
is( $reps[0]->get_field('address')->label, 'label 1' );
is( $reps[1]->get_field('id')->default, '3' );
is( $reps[1]->get_field('address')->default, 'office' );
is( $reps[1]->get_field('address')->label, 'label 2' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/ 0000775 0001751 0001752 00000000000 13262760616 015322 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_many_new_exceed_max.t 0000644 0001751 0001752 00000002244 13262760616 025551 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib qw(t/lib lib);
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable_many_new.yml');
my $schema = new_schema();
my $user_rs = $schema->resultset('User');
my $address_rs = $schema->resultset('Address');
{
$form->process(
{
'id' => '',
'name' => 'new nick',
'master' => 1,
'count' => 2,
'addresses_1.id' => '',
'addresses_1.address' => 'new home',
'addresses_2.id' => '',
'addresses_2.address' => 'new office',
'addresses_3.id' => '',
'addresses_3.address' => 'new office2',
}
);
ok( $form->submitted_and_valid );
my $row = $user_rs->new( {} );
$form->model('DBIC')->update($row);
my $user = $user_rs->find(1);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
# 3rd address isn't inserted
is( scalar @add, 2 );
is( $add[0]->id, 1 );
is( $add[0]->address, 'new home' );
is( $add[1]->id, 2 );
is( $add[1]->address, 'new office' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_read_only.yml 0000644 0001751 0001752 00000000352 13262760616 025514 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Checkboxgroup
name: bands
model_config:
read_only: 1
options_from_model: 0
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_implicit.yml 0000644 0001751 0001752 00000000561 13262760616 024573 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
model_config:
empty_rows: 1
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/ignore_if_empty.yml 0000644 0001751 0001752 00000000174 13262760616 021224 0 ustar carl carl ---
model_config:
resultset: User
elements:
- type: Password
name: name
model_config:
ignore_if_empty: 1
HTML-FormFu-Model-DBIC-2.03/t/update/ignore_if_empty.t 0000644 0001751 0001752 00000001467 13262760616 020674 0 ustar carl carl 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/update/ignore_if_empty.yml');
my $schema = new_schema();
my $rs = $schema->resultset('User')->create( {
master => 1,
name => "foo",
title => 'bar'
} );
is( $rs->name, "foo" );
{
$form->process( { name => 'test' } );
$form->model->update($rs);
is( $rs->name, "test" );
}
{
$form->process( { name => undef } );
$form->model->update($rs);
is( $rs->name, "test" );
}
{
$form->process( { name => 0 } );
$form->model->update($rs);
is( $rs->name, "0" );
}
{
$form->process( { name => " " } );
$form->model->update($rs);
is( $rs->name, " " );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_one.yml 0000644 0001751 0001752 00000000406 13262760616 017457 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Block
nested_name: user
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/has_one_no_id.yml 0000644 0001751 0001752 00000000337 13262760616 020632 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Block
nested_name: user
elements:
- type: Text
name: name
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/opt_accessor.t 0000644 0001751 0001752 00000001613 13262760616 020172 0 ustar carl carl use strict;
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/update/opt_accessor.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', {
name => 'mr. bar',
} );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', {
name => 'mr. foo',
} );
}
{
$form->process( {
id => 2,
fullname => 'mr billy bob',
} );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $row = $schema->resultset('User')->find(2);
is( $row->title, 'mr' );
is( $row->name, 'billy bob' );
is( $row->fullname, 'mr billy bob' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/methods.yml 0000644 0001751 0001752 00000000237 13262760616 017510 0 ustar carl carl ---
elements:
- type: Text
name: method_test
- type: Select
name: method_select_test
- type: Checkbox
name: method_checkbox_test
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable.t 0000644 0001751 0001752 00000003713 13262760616 021474 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# address 2
$u2->create_related( 'addresses', { address => 'home' } );
# address 3
$u2->create_related( 'addresses', { address => 'office' } );
}
{
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 2,
'addresses_1.id' => 2,
'addresses_1.address' => 'new home',
'addresses_2.id' => 3,
'addresses_2.address' => 'new office',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
is( scalar @add, 2 );
is( $add[0]->id, 2 );
is( $add[0]->address, 'new home' );
is( $add[1]->id, 3 );
is( $add[1]->address, 'new office' );
}
my $el = $form->get_all_element({name => "name"});
$el->model_config->{read_only} = 1;
{
$form->process( {
'id' => 2,
'name' => 'new new nick',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_restricted.yml 0000644 0001751 0001752 00000000362 13262760616 025711 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Checkboxgroup
name: bands
model_config:
model: Bands
condition:
manager: 1
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/basic_create.t 0000644 0001751 0001752 00000003010 13262760616 020103 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 10;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/basic.yml');
my $schema = new_schema();
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',
checkbox_col => 'foo',
select_col => '2',
radio_col => 'yes',
radiogroup_col => '3',
} );
{
my $row = $rs->new( {} );
$form->model->update($row);
}
{
my $row = $rs->find(2);
is( $row->text_col, 'a2' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/opt_accessor_nested.yml 0000644 0001751 0001752 00000000300 13262760616 022062 0 ustar carl carl ---
auto_fieldset:
nested_name: foo
elements:
- type: Hidden
name: id
- type: Text
name: fullname
model_config:
accessor: fullname
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/opt_accessor.yml 0000644 0001751 0001752 00000000257 13262760616 020533 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: fullname
model_config:
accessor: fullname
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/add_valid.t 0000644 0001751 0001752 00000001704 13262760616 017416 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/basic.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# Fake submitted form
$form->process( {
id => 1,
text_col => 'a',
password_col => 'b',
checkbox_col => 'foo',
select_col => '2',
radio_col => 'yes',
radiogroup_col => '3',
} );
{
$form->add_valid( 'not_in_form', 'xyz' );
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->radio_col, 'yes' );
is( $row->radiogroup_col, '3' );
is( $row->not_in_form, 'xyz' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_required_when.t 0000644 0001751 0001752 00000003551 13262760616 025266 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable_new_required_when.yml');
# a form is created with 'empty_rows' => 2
# but only 1 new row is filled in
# test using a Required constraint
# with 'when' pointing to the PK field
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# address 2
$u2->create_related( 'addresses', { address => 'home' } );
# address 3
$u2->create_related( 'addresses', { address => 'office' } );
}
{
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 4,
'addresses_1.id' => 2,
'addresses_1.address' => 'new home',
'addresses_2.id' => 3,
'addresses_2.address' => 'new office',
'addresses_3.id' => '',
'addresses_3.address' => 'new address',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
is( scalar @add, 3 );
is( $add[0]->id, 2 );
is( $add[0]->address, 'new home' );
is( $add[1]->id, 3 );
is( $add[1]->address, 'new office' );
is( $add[2]->id, 4 );
is( $add[2]->address, 'new address' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_repeatable_new.yml 0000644 0001751 0001752 00000000555 13262760616 023577 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: bands
counter_name: count
model_config:
new_rows_max: 1
elements:
- type: Hidden
name: id
- type: Text
name: band
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_empty.t 0000644 0001751 0001752 00000003311 13262760616 023555 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable_new.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
}
# rows we're going to use
{
# should get user id 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
$u2->insert;
# should get address id 2
$u2->create_related( 'addresses', { address => 'home' } );
# should get address id 3
$u2->create_related( 'addresses', { address => 'office' } );
}
{
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 3,
'addresses_1.id' => 2,
'addresses_1.address' => 'new home',
'addresses_2.id' => 3,
'addresses_2.address' => 'new office',
'addresses_3.id' => '',
'addresses_3.address' => '',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
is( scalar @add, 2 );
# empty address not inserted
is( $add[0]->id, 2 );
is( $add[0]->address, 'new home' );
is( $add[1]->id, 3 );
is( $add[1]->address, 'new office' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable.yml 0000644 0001751 0001752 00000000513 13262760616 022025 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_repeatable_new.t 0000644 0001751 0001752 00000002746 13262760616 023245 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/many_to_many_repeatable_new.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')-> create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# band 1
$u1->add_to_bands({ band => 'a' });
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# band 2,3
$u2->add_to_bands({ band => 'b' });
$u2->add_to_bands({ band => 'c' });
}
{
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 3,
'bands_1.id' => 2,
'bands_1.band' => 'b++',
'bands_2.id' => 3,
'bands_2.band' => 'c++',
'bands_3.id' => '',
'bands_3.band' => 'd++'
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->bands->all;
is( scalar @add, 3 );
is( $add[0]->id, 2 );
is( $add[0]->band, 'b++' );
is( $add[1]->id, 3 );
is( $add[1]->band, 'c++' );
is( $add[2]->id, 4 );
is( $add[2]->band, 'd++' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to.t 0000644 0001751 0001752 00000001526 13262760616 017644 0 ustar carl carl 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/default_values/belongs_to_lookup_table.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# Fake submitted form
$form->process( {
"id" => 3,
"text_col" => 'a',
'type_id' => '1',
'type2_id' => '1',
} );
# filler rows
{
# insert some entries we'll ignore, so our rels don't have same ids
$rs->create( { id => 1 } );
$rs->create( { id => 2 } );
}
{
# master 3
my $master = $rs->create( { text_col => 'b', type_id => 2, type2_id => 2 } );
$form->model->update($master);
}
{
my $row = $rs->find(3);
is( $row->type->id, '1' );
is( $row->type2->id, '1' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/opt_accessor_nested.t 0000644 0001751 0001752 00000001672 13262760616 021541 0 ustar carl carl use strict;
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/update/opt_accessor_nested.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', {
name => 'mr. bar',
} );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', {
name => 'mr. foo',
} );
}
{
$form->process( {
'foo.id' => 2,
'foo.fullname' => 'mr billy bob',
} );
my $row = $schema->resultset('User')->find(2);
$form->model->update( $row, { nested_base => 'foo' } );
}
{
my $row = $schema->resultset('User')->find(2);
is( $row->title, 'mr' );
is( $row->name, 'billy bob' );
is( $row->fullname, 'mr billy bob' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_delete_true.t 0000644 0001751 0001752 00000003321 13262760616 024050 0 ustar carl carl 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/update/has_many_repeatable_delete_true.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
}
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# adresses 2,3,4
$u2->create_related( 'addresses', { address => 'home' } );
$u2->create_related( 'addresses', { address => 'office' } );
$u2->create_related( 'addresses', { address => 'temp' } );
}
{
# changing address 2 and deleting address 3+4
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 3,
'addresses_1.id' => 2,
'addresses_1.address' => 'new home',
'addresses_1.delete' => 1,
'addresses_2.id' => 3,
'addresses_2.address' => 'new office',
'addresses_3.id' => 4,
'addresses_3.address' => 'new office',
'addresses_3.delete' => 1,
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
is( scalar @add, 1 );
is( $add[0]->id, 3 );
is( $add[0]->address, 'new office' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/unchecked_not_null_checkbox.t 0000644 0001751 0001752 00000001270 13262760616 023216 0 ustar carl carl 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/update/basic.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
{
my $row = $rs->new_result( { checkbox_col => 'xyzfoo', } );
$row->insert;
}
# an unchecked Checkbox causes no key/value to be submitted at all
# this is a problem for NOT NULL columns
# ensure the column's default value gets inserted
$form->process( { id => 1, } );
{
my $row = $rs->find(1);
$form->model->update($row);
}
{
my $row = $rs->find(1);
is( $row->checkbox_col, '0' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/nested_repeatable_write.yml 0000644 0001751 0001752 00000000726 13262760616 022730 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Hidden
name: sched_count
- type: Repeatable
nested_name: schedules
counter_name: sched_count
elements:
- type: Hidden
name: id
- type: Text
name: note
- type: Hidden
name: count
- type: Repeatable
nested_name: tasks
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: detail
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_unselected.t 0000644 0001751 0001752 00000002522 13262760616 025336 0 ustar carl carl use strict;
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/update/many_to_many_checkboxgroup.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')-> create({ id => 1 });
my $band1;
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'John' } );
# band 1
$band1 = $u1->add_to_bands({ band => 'the beatles' });
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'Paul', } );
# band 2
$u2->add_to_bands({ band => 'wings' });
# band 3 - not used
$schema->resultset('Band')->create({ band => 'the kinks' });
# band 1
$u2->add_to_bands($band1);
}
# currently,
# user [2] => bands [2, 1]
{
$form->process( {
id => 2,
name => 'Paul McCartney',
# no bands - if you unselect all options,
# the browser doesn't submit that param at all
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $row = $schema->resultset('User')->find(2);
is( $row->name, 'Paul McCartney' );
my @bands = $row->bands->all;
is( scalar(@bands), 0 );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_one_select.t 0000755 0001751 0001752 00000002704 13262760616 020466 0 ustar carl carl 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/update/has_one_select.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $rs = $schema->resultset('Master');
# filler rows
{
# master 1
$rs->create( { text_col => 'xxx' } );
# master 2
my $m2 = $rs->create( { text_col => 'yyy' } );
# user 1
$m2->create_related( 'user', { name => 'zzz' } );
}
# rows we're going to use
{
# master 3
my $m3 = $rs->create( { text_col => 'b' } );
# user 2
$m3->create_related( 'user', { name => 'xxx' } );
}
{
$form->process( {
"id" => 3,
"text_col" => 'a',
"user" => 1,
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('Master')->find(3);
$form->model->update($row);
is($row->user->id, 1);
$form->process( {
"id" => 3,
"text_col" => 'a',
"user" => 99,
} );
ok( $form->submitted_and_valid );
}
{
my $row = $schema->resultset('Master')->find(3);
$form->model->update($row);
is($row->user->id, 1);
$form = HTML::FormFu->new;
$form->stash->{schema} = $schema;
$form->load_config_file('t/update/has_one_select.yml');
$form->model->default_values($row);
$form->process;
like($form, qr/value="1" selected=/);
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_delete_true.yml 0000644 0001751 0001752 00000000652 13262760616 024412 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Checkbox
name: delete
model_config:
delete_if_true: 1
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/might_have_delete_if_empty.yml 0000644 0001751 0001752 00000000426 13262760616 023376 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Block
nested_name: note
elements:
- type: Textarea
name: note
model_config:
delete_if_empty: 1
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/might_have.t 0000644 0001751 0001752 00000002046 13262760616 017622 0 ustar carl carl use strict;
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/update/might_have.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler rows
{
# master 1
$rs->create( { text_col => 'xxx' } );
# master 2
my $m2 = $rs->create( { text_col => 'yyy' } );
# note 1
$m2->new_related( 'note', { note => 'zzz' } );
}
# rows we're going to use
{
# master 3
my $m3 = $rs->create( { text_col => 'b' } );
# note 2
$m3->new_related( 'note', { note => 'aaa' } );
}
{
$form->process( {
"id" => 3,
"text_col" => 'a',
"note.id" => 2,
"note.note" => 'abc',
} );
my $row = $schema->resultset('Master')->find(3);
$form->model->update($row);
}
{
my $row = $schema->resultset('Master')->find(3);
is( $row->text_col, 'a' );
my $note = $row->note;
is( $note->id, 2 );
is( $note->note, 'abc' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_one.t 0000644 0001751 0001752 00000002120 13262760616 017114 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 4;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_one.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler rows
{
# master 1
$rs->create( { text_col => 'xxx' } );
# master 2
my $m2 = $rs->create( { text_col => 'yyy' } );
# user 1
$m2->create_related( 'user', { name => 'zzz' } );
}
# rows we're going to use
{
# master 3
my $m3 = $rs->create( { text_col => 'b' } );
# user 2
$m3->create_related( 'user', { name => 'xxx' } );
}
{
$form->process( {
"id" => 3,
"text_col" => 'a',
"user.id" => 2,
"user.name" => 'bar',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('Master')->find(3);
$form->model->update($row);
}
{
my $row = $schema->resultset('Master')->find(3);
is( $row->text_col, 'a' );
my $user = $row->user;
is( $user->id, 2 );
is( $user->name, 'bar' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_one_create.t 0000644 0001751 0001752 00000001762 13262760616 020452 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 4;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_one.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler rows
{
# master 1
$rs->create( { text_col => 'xxx' } );
# master 2
my $m2 = $rs->create( { text_col => 'yyy' } );
# user 1
$m2->create_related( 'user', { name => 'zzz' } );
}
# rows we're going to use
{
# master 3
my $m3 = $rs->create( { text_col => 'b' } );
}
{
$form->process( {
"id" => 3,
"text_col" => 'a',
"user.name" => 'bar',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('Master')->find(3);
$form->model->update($row);
}
{
my $row = $schema->resultset('Master')->find(3);
is( $row->text_col, 'a' );
my $user = $row->user;
is( $user->id, 2 );
is( $user->name, 'bar' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_select_additive.yml 0000644 0001751 0001752 00000000431 13262760616 023743 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Select
name: bands
multiple: 1
model_config:
additive: 1
options_from_model: 0
link_values:
rating: 100
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_repeatable.yml 0000644 0001751 0001752 00000000503 13262760616 022717 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: bands
counter_name: count
elements:
- type: Hidden
name: id
- type: Text
name: band
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_select.yml 0000644 0001751 0001752 00000000262 13262760616 022074 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Select
name: bands
multiple: 1
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_select.yml 0000644 0001751 0001752 00000000171 13262760616 021534 0 ustar carl carl ---
model_config:
resultset: Note
elements:
- name: id
- name: note
- name: master
type: Select HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_create.t 0000644 0001751 0001752 00000001270 13262760616 021163 0 ustar carl carl 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->populate({
elements => [
{
name => 'band',
},
{
type => 'Block',
nested_name => 'manager',
elements => {
name => 'name',
}
}
]
});
my $schema = new_schema();
my $rs = $schema->resultset('Band');
my $band = $rs->new_result({});
$form->process({ band => 'The Foobars', 'manager.name' => 'Mr Foo' });
$form->model('DBIC')->update($band);
is($band->band, 'The Foobars');
is($band->manager->name, 'Mr Foo');
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new.t 0000644 0001751 0001752 00000003302 13262760616 022337 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable_new.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# address 2
$u2->create_related( 'addresses', { address => 'home' } );
# address 3
$u2->create_related( 'addresses', { address => 'office' } );
}
{
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 3,
'addresses_1.id' => 2,
'addresses_1.address' => 'new home',
'addresses_2.id' => 3,
'addresses_2.address' => 'new office',
'addresses_3.id' => '',
'addresses_3.address' => 'new address',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
is( scalar @add, 3 );
is( $add[0]->id, 2 );
is( $add[0]->address, 'new home' );
is( $add[1]->id, 3 );
is( $add[1]->address, 'new office' );
is( $add[2]->id, 4 );
is( $add[2]->address, 'new address' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/nested_create_checkbox.t 0000644 0001751 0001752 00000001140 13262760616 022154 0 ustar carl carl 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/update/nested.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# Fake submitted form
$form->process( {
"foo.id" => 1,
"foo.text_col" => 'a',
} );
{
my $row = $rs->new( {} );
$form->model->update( $row, { nested_base => 'foo' } );
}
{
my $row = $rs->find(1);
is( $row->text_col, 'a' );
# check default
is( $row->checkbox_col, 0 );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup.yml 0000644 0001751 0001752 00000000251 13262760616 023456 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Checkboxgroup
name: bands
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/might_have.yml 0000644 0001751 0001752 00000000412 13262760616 020153 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Block
nested_name: note
elements:
- type: Hidden
name: id
- type: Textarea
name: note
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_repeatable.t 0000644 0001751 0001752 00000002746 13262760616 022374 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/many_to_many_repeatable.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')-> create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# band 1
$u1->add_to_bands({ band => 'a' });
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# band 2,3,4
$u2->add_to_bands({ band => 'b' });
$u2->add_to_bands({ band => 'c' });
$u2->add_to_bands({ band => 'd' });
}
{
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 2,
'bands_1.id' => 2,
'bands_1.band' => 'b++',
'bands_2.id' => 3,
'bands_2.band' => 'c++',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->bands->all;
is( scalar @add, 3 );
is( $add[0]->id, 2 );
is( $add[0]->band, 'b++' );
is( $add[1]->id, 3 );
is( $add[1]->band, 'c++' );
# band 4 should be unchanged
is( $add[2]->id, 4 );
is( $add[2]->band, 'd' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup.t 0000644 0001751 0001752 00000002523 13262760616 023124 0 ustar carl carl 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/update/many_to_many_checkboxgroup.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')-> create({ id => 1 });
my $band1;
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'John' } );
# band 1
$band1 = $u1->add_to_bands({ band => 'the beatles' });
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'Paul', } );
# band 2
$u2->add_to_bands({ band => 'wings' });
# band 3 - not used
$schema->resultset('Band')->create({ band => 'the kinks' });
# band 1
$u2->add_to_bands($band1);
}
# currently,
# user [2] => bands [2, 1]
{
$form->process( {
id => 2,
name => 'Paul McCartney',
bands => [ 1, 3 ],
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $row = $schema->resultset('User')->find(2);
is( $row->name, 'Paul McCartney' );
my @bands = $row->bands->all;
is( scalar @bands, 2 );
my @id = sort map { $_->id } @bands;
is( $id[0], 1 );
is( $id[1], 3 );
}
HTML-FormFu-Model-DBIC-2.03/t/update/column_without_field.yml 0000644 0001751 0001752 00000000204 13262760616 022262 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_create_required.t 0000644 0001751 0001752 00000001277 13262760616 023072 0 ustar carl carl 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->populate({
elements => [
{
name => 'band',
},
{
type => 'Block',
nested_name => 'manager',
elements => {
name => 'name',
}
}
]
});
my $schema = new_schema();
my $rs = $schema->resultset('ManagedBand');
my $band = $rs->new_result({});
$form->process({ band => 'The Foobars', 'manager.name' => 'Mr Foo' });
$form->model('DBIC')->update($band);
is($band->band, 'The Foobars');
is($band->manager->name, 'Mr Foo');
HTML-FormFu-Model-DBIC-2.03/t/update/might_have_delete_if_empty.t 0000644 0001751 0001752 00000002261 13262760616 023037 0 ustar carl carl 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/update/might_have_delete_if_empty.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
my $note_rs = $schema->resultset('Note');
# Fake submitted form
$form->process( {
"id" => 3,
"text_col" => 'a',
"note.note" => '',
} );
{
# insert some entries we'll ignore, so our rels don't have same ids
# test id 1
my $t1 = $rs->new_result( { text_col => 'xxx' } );
$t1->insert;
# test id 2
my $t2 = $rs->new_result( { text_col => 'yyy' } );
$t2->insert;
# note id 1
my $n1 = $t2->new_related( 'note', { note => 'zzz' } );
$n1->insert;
# should get master id 3
my $master = $rs->new( { text_col => 'b' } );
$master->insert;
# should get note id 2
my $note = $master->new_related( 'note', { note => 'abc' } );
$note->insert;
$form->model->update($master);
}
{
my $row = $rs->find(3);
is( $row->text_col, 'a' );
my $note = $row->note;
ok( !defined $note );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_many_new.t 0000644 0001751 0001752 00000002056 13262760616 023370 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib qw(t/lib lib);
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable_many_new.yml');
my $schema = new_schema();
my $user_rs = $schema->resultset('User');
my $address_rs = $schema->resultset('Address');
{
$form->process(
{
'id' => '',
'name' => 'new nick',
'master' => 1,
'count' => 2,
'addresses_1.id' => '',
'addresses_1.address' => 'new home',
'addresses_2.id' => '',
'addresses_2.address' => 'new office',
}
);
ok( $form->submitted_and_valid );
my $row = $user_rs->new( {} );
$form->model('DBIC')->update($row);
my $user = $user_rs->find(1);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
is( scalar @add, 2 );
is( $add[0]->id, 1 );
is( $add[0]->address, 'new home' );
is( $add[1]->id, 2 );
is( $add[1]->address, 'new office' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/basic.yml 0000644 0001751 0001752 00000001432 13262760616 017124 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Password
name: password_col
- type: Checkbox
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
name: radio_col
value: no
- type: Radiogroup
name: radiogroup_col
values: [1, 2, 3]
- type: Checkboxgroup
name: array_col
options:
- [one]
- [two]
- [three]
- type: Text
name: date_col
- type: Text
name: unknown_col
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_many_new.yml 0000644 0001751 0001752 00000000650 13262760616 023724 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Text
name: master
- type: Repeatable
nested_name: addresses
counter_name: count
model_config:
new_rows_max: 2
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/nested_name_accessor.t 0000644 0001751 0001752 00000002265 13262760616 021656 0 ustar carl carl 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/default_values/nested_name_accessor.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', {
name => 'mr. bar',
} );
# hasmanys 2,3
$u1->create_related( 'hasmanys', { key => 'bar', value => 'a' } );
$u1->create_related( 'hasmanys', { key => 'foo', value => 'b' } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', {
name => 'mr. foo',
} );
# hasmanys 3 4
$u2->create_related( 'hasmanys', { key => 'bar', value => 'c' } );
$u2->create_related( 'hasmanys', { key => 'foo', value => 'd' } );
}
{
$form->process( {
'name' => 'Mr. Foo',
'foo.value' => 'e',
} );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $row = $schema->resultset('User')->find(2);
is ( $row->name, 'Mr. Foo' );
is ( $row->foo->value, 'e' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/methods.t 0000644 0001751 0001752 00000002141 13262760616 017146 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $schema = new_schema();
my $rs = $schema->resultset('Master');
{
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/methods.yml');
# Fake submitted form
$form->process( {
method_test => 'apejens',
method_checkbox_test => 1,
} );
{
my $row = $rs->new( {} );
$form->model->update($row);
}
{
my $row = $rs->find(1);
is( $row->text_col, 'apejens' );
is( $row->method_test, 'apejens' );
is( $row->checkbox_col, 1);
is( $row->method_checkbox_test, 1);
}
}
{
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/methods.yml');
$form->process({
method_test => 'apejens2',
});
my $row = $rs->find(1);
$form->model->update($row);
is( $row->text_col, 'apejens2' );
is( $row->checkbox_col, 0);
is( $row->method_checkbox_test, 0);
}
HTML-FormFu-Model-DBIC-2.03/t/update/basic_update.t 0000644 0001751 0001752 00000003001 13262760616 020122 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/basic.yml');
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' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_lookup_table_combobox.yml 0000644 0001751 0001752 00000000561 13262760616 024630 0 ustar carl carl ---
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
HTML-FormFu-Model-DBIC-2.03/t/update/null_if_empty.yml 0000644 0001751 0001752 00000000226 13262760616 020711 0 ustar carl carl ---
model_config:
resultset: User
elements:
- type: Text
name: name
- type: Text
name: title
model_config:
null_if_empty: 1
HTML-FormFu-Model-DBIC-2.03/t/update/nested_create.t 0000644 0001751 0001752 00000002127 13262760616 020314 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/nested.yml');
my $schema = new_schema();
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' )
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_select.t 0000644 0001751 0001752 00000002515 13262760616 021541 0 ustar carl carl 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/update/many_to_many_select.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')-> create({ id => 1 });
my $band1;
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'John' } );
# band 1
$band1 = $u1->add_to_bands({ band => 'the beatles' });
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'Paul', } );
# band 2
$u2->add_to_bands({ band => 'wings' });
# band 3 - not used
$schema->resultset('Band')->create({ band => 'the kinks' });
# band 1
$u2->add_to_bands($band1);
}
# currently,
# user [2] => bands [2, 1]
{
$form->process( {
id => 2,
name => 'Paul McCartney',
bands => [ 1, 3 ],
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $row = $schema->resultset('User')->find(2);
is( $row->name, 'Paul McCartney' );
my @bands = $row->bands->all;
is( scalar @bands, 2 );
my @id = sort map { $_->id } @bands;
is( $id[0], 1 );
is( $id[1], 3 );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many-has_many.t 0000644 0001751 0001752 00000006125 13262760616 022000 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 15;
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/many_to_many-has_many.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create( { id => 1 } );
# filler rows
{
# user 1
my $user = $master->create_related( 'user', { name => 'filler', } );
# band 1
$user->add_to_bands( { band => 'a', } );
# address 1
$user->add_to_addresses( { address => 'b' } );
# user 2,3,4
$master->create_related( 'user', { name => 'filler2', } );
$master->create_related( 'user', { name => 'filler3', } );
$master->create_related( 'user', { name => 'filler4', } );
}
# rows we're going to use
{
# band 2
my $band = $schema->resultset('Band')->create( { band => 'band 2' } );
# user 5,6
my $user1
= $band->add_to_users( { name => 'user 5', master => $master->id } );
my $user2
= $band->add_to_users( { name => 'user 6', master => $master->id } );
# address 2,3
$user1->create_related( 'addresses', { address => 'add 2' } );
$user1->create_related( 'addresses', { address => 'add 3' } );
# address 4
$user2->create_related( 'addresses', { address => 'add 4' } );
}
{
$form->process( {
'band' => 'band 2 edit',
'count' => 2,
'users_1.id' => 5,
'users_1.name' => 'user 5 edit',
'users_1.count' => 2,
'users_1.addresses_1.id' => 2,
'users_1.addresses_1.address' => 'add 2 edit',
'users_1.addresses_2.id' => 3,
'users_1.addresses_2.address' => 'add 3 edit',
'users_2.id' => 6,
'users_2.name' => 'user 6 edit',
'users_2.count' => 1,
'users_2.addresses_1.id' => 4,
'users_2.addresses_1.address' => 'add 4 edit',
'submit' => 'Submit',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('Band')->find(2);
$form->model->update($row);
}
{
my $band = $schema->resultset('Band')->find(2);
is( $band->band, 'band 2 edit' );
my @user = $band->users->all;
is( scalar @user, 2 );
# user 5
{
is( $user[0]->id, 5 );
is( $user[0]->name, 'user 5 edit' );
my @address = $user[0]->addresses->all;
is( scalar @address, 2 );
# address 2
is( $address[0]->id, 2 );
is( $address[0]->address, 'add 2 edit' );
# address 3
is( $address[1]->id, 3 );
is( $address[1]->address, 'add 3 edit' );
}
# user 6
{
is( $user[1]->id, 6 );
is( $user[1]->name, 'user 6 edit' );
my @address = $user[1]->addresses->all;
is( scalar @address, 1 );
# address 3
is( $address[0]->id, 4 );
is( $address[0]->address, 'add 4 edit' );
}
}
HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_combobox.t 0000644 0001751 0001752 00000001714 13262760616 021533 0 ustar carl carl 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/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
$rs->create( { id => 1 } );
$rs->create( { id => 2 } );
}
{
# master 3
my $master = $rs->create( {
text_col => 'b',
type_id => 2,
type2_id => 2,
} );
# Fake submitted form
$form->process( {
"id" => 3,
"text_col" => 'a',
'type_select' => '1',
'type2_id' => '1',
} );
$form->model->update($master);
}
{
my $row = $rs->find(3);
is( $row->type->id, '1' );
is( $row->type2->id, '1' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_restricted.t 0000644 0001751 0001752 00000003067 13262760616 025360 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 5;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use HTMLFormFu::MockContext;
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/many_to_many_checkboxgroup_restricted.yml');
my $schema = new_schema();
my $context = HTMLFormFu::MockContext->new( {
model => $schema->resultset('Band'),
} );
$form->stash( { context => $context } );
my $master = $schema->resultset('Master')->create({ id => 1 });
my $band1;
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'John' } );
# band 1
$band1 = $u1->add_to_bands( { band => 'the beatles', manager => 1 } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'Paul' } );
$u2->add_to_bands($band1);
# band 2
$schema->resultset('Band')->create( { band => 'wings', manager => 1 } );
# band 3
$u2->add_to_bands( { band => 'the kinks', manager => 2 } );
}
# currently,
# user [2] => bands [3, 1]
{
$form->process( {
id => 2,
name => 'Paul McCartney',
bands => [ 1 ],
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $row = $schema->resultset('User')->find(2);
is( $row->name, 'Paul McCartney' );
my @bands = $row->bands->all;
is( scalar @bands, 2 );
my @id = sort map { $_->id } @bands;
is( $id[0], 1 );
is( $id[1], 3 ); # 3 should not have been touched
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_one_select.yml 0000644 0001751 0001752 00000000315 13262760616 021015 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Select
name: user
model_config:
resultset: User
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_dependon.t 0000644 0001751 0001752 00000003575 13262760616 024227 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable_new_dependon.yml');
# a form is created with 'empty_rows' => 2
# but only 1 new row is filled in
# test a DependOn constraint attached to the PK column
# with 'others' listing the required fields
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# address 2
$u2->create_related( 'addresses', { address => 'home' } );
# address 3
$u2->create_related( 'addresses', { address => 'office' } );
}
{
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 4,
'addresses_1.id' => 2,
'addresses_1.address' => 'new home',
'addresses_2.id' => 3,
'addresses_2.address' => 'new office',
'addresses_3.id' => '',
'addresses_3.address' => 'new address',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
is( scalar @add, 3 );
is( $add[0]->id, 2 );
is( $add[0]->address, 'new home' );
is( $add[1]->id, 3 );
is( $add[1]->address, 'new office' );
is( $add[2]->id, 4 );
is( $add[2]->address, 'new address' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_required_when.yml 0000644 0001751 0001752 00000000735 13262760616 025625 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
model_config:
empty_rows: 2
elements:
- type: Hidden
name: id
- type: Text
name: address
constraints:
- type: Required
when:
field: 'addresses.id'
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_date.yml 0000644 0001751 0001752 00000000751 13262760616 023677 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Text
name: text_col
- type: Repeatable
nested_name: schedules
counter_name: count
model_config:
empty_rows: 1
new_rows_max: 1
elements:
- type: Hidden
name: id
- type: Date
name: date
auto_inflate: 1
constraints:
- Required
- name: note
constraints:
- Required
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/nested.yml 0000644 0001751 0001752 00000001307 13262760616 017326 0 ustar carl carl ---
auto_fieldset:
nested_name: foo
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Password
name: password_col
- type: Checkbox
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
name: radio_col
value: no
- type: Radiogroup
name: radiogroup_col
values: [1, 2, 3]
- type: Text
name: date_col
- type: Text
name: unknown_col
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_select_two.yml 0000644 0001751 0001752 00000000201 13262760616 022417 0 ustar carl carl ---
model_config:
resultset: TwoNote
elements:
- name: two_note_id
- name: note
- name: id
type: Select HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_select.t 0000644 0001751 0001752 00000002346 13262760616 021204 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 4;
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_select.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $rs = $schema->resultset('Master');
$rs->create( { id => 1 } );
$rs->create( { id => 2 } );
my $master = $rs->create( { text_col => 'b', type_id => 2, type2_id => 2 } );
$form->process( { master => 2, note => 'foo' } );
$form->model->create;
my $note = $schema->resultset("Note")->find(1);
is($note->master->id, 2);
is($note->note, 'foo');
}
{
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/belongs_to_select_two.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $rs = $schema->resultset('Master');
$rs->create( { id => 4 } );
$rs->create( { id => 5 } );
my $master = $rs->create( { text_col => 'b', type_id => 2, type2_id => 2 } );
$form->process( { id => 4, note => 'foo' } );
$form->model->create;
my $note = $schema->resultset("TwoNote")->find(1);
is($note->id->id, 4);
is($note->note, 'foo');
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_date.t 0000644 0001751 0001752 00000003536 13262760616 023345 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
use DateTime;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable_new_date.yml');
my $schema = new_schema();
my $master_rs = $schema->resultset('Master');
# filler rows
{
# user 1
my $m1 = $master_rs->create( { text_col => 'foo' } );
# schedule 1
$m1->create_related( 'schedules', {
date => DateTime->new( year => 2008, month => 7, day => 16 ),
note => 'a',
} );
# schedule 2
$m1->create_related( 'schedules', {
date => DateTime->new( year => 2008, month => 7, day => 17 ),
note => 'b',
} );
}
# rows we're going to use
{
# user 2
my $m2 = $master_rs->create( { text_col => 'orig text', } );
# schedule 3
$m2->create_related( 'schedules', {
date => DateTime->new( year => 2008, month => 7, day => 18 ),
note => 'c',
} );
}
{
$form->process( {
'text_col' => 'new text',
'count' => 1,
'schedules_1.id' => 3,
'schedules_1.date_day' => '19',
'schedules_1.date_month' => '07',
'schedules_1.date_year' => '2008',
'schedules_1.note' => 'hi',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('Master')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('Master')->find(2);
is( $user->text_col, 'new text' );
my @schedule = $user->schedules->all;
is( scalar @schedule, 1 );
is( $schedule[0]->id, 3 );
my $date = $schedule[0]->date;
isa_ok( $date, 'DateTime' );
is( $date->year, 2008 );
is( $date->month, 7 );
is( $date->day, 19 );
is( $schedule[0]->note, 'hi' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/null_if_empty.t 0000644 0001751 0001752 00000002211 13262760616 020347 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/null_if_empty.yml');
my $schema = new_schema();
my $rs = $schema->resultset('User')->create( {
name => "foo",
} );
is( $rs->name, "foo" );
{
$form->process( { name => "foo", title => "" } );
$form->model->update($rs);
is( $rs->title, undef );
}
{
$form->process( { name => "foo", title => 'test' } );
$form->model->update($rs);
is( $rs->title, "test" );
}
{
$form->process( { name => "foo", title => undef } );
$form->model->update($rs);
is( $rs->title, undef );
}
{
$form->process( { name => "foo", title => 0 } );
$form->model->update($rs);
is( $rs->title, "0" );
}
{
$form->process( { name => "foo", title => " " } );
$form->model->update($rs);
is( $rs->title, " " );
}
{
$form->get_element( name => 'title' )->model_config->{null_if_empty} = 0;
$form->process( { name => "foo", title => "" } );
$form->model->update($rs);
is( $rs->title, "" );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_checkboxgroup_read_only.t 0000644 0001751 0001752 00000002524 13262760616 025161 0 ustar carl carl 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/update/many_to_many_checkboxgroup_read_only.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')-> create({ id => 1 });
my $band1;
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'John' } );
# band 1
$band1 = $u1->add_to_bands({ band => 'the beatles' });
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'Paul', } );
# band 2
$u2->add_to_bands({ band => 'wings' });
# band 3 - not used
$schema->resultset('Band')->create({ band => 'the kinks' });
# band 1
$u2->add_to_bands($band1);
}
# currently,
# user [2] => bands [2, 1]
{
$form->process( {
id => 2,
name => 'John Lennon',
bands => [ 2 ],
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $row = $schema->resultset('User')->find(2);
is( $row->name, 'John Lennon' );
my @bands = $row->bands->all;
is( scalar @bands, 2 );
my @id = sort map { $_->id } @bands;
is( $id[0], 1 );
is( $id[1], 2 );
}
HTML-FormFu-Model-DBIC-2.03/t/update/column_without_field.t 0000644 0001751 0001752 00000001443 13262760616 021732 0 ustar carl carl use strict;
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/update/column_without_field.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
{
my $row = $rs->new_result( {
text_col => 'a',
password_col => 'd',
checkbox_col => 'g'
} );
$row->insert;
}
# Fake submitted form
$form->process( {
id => 1,
text_col => 'abc',
} );
{
my $row = $rs->find(1);
$form->model->update($row);
}
{
my $row = $rs->find(1);
is( $row->text_col, 'abc' );
# original values still there
is( $row->password_col, 'd' );
is( $row->checkbox_col, 'g' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new.yml 0000644 0001751 0001752 00000000607 13262760616 022702 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
model_config:
empty_rows: 1
new_rows_max: 1
elements:
- type: Hidden
name: id
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/nested_repeatable_write.t 0000644 0001751 0001752 00000003606 13262760616 022372 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 7;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/nested_repeatable_write.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# first sub-record
{
# schedule 1
my $u1 = $master->create_related( 'schedules', { note => 'some appointment',
date => '02-02-2009' } );
# task 1
$u1->create_related( 'tasks' => { detail => 'associated to do item' } );
}
# second sub-record
{
# schedule 2
my $u2 = $master->create_related( 'schedules', { note => 'some other appointment',
date => '03-03-2009' } );
# task 2
$u2->create_related( 'tasks', { detail => 'action item 1' } );
# task 3
$u2->create_related( 'tasks', { detail => 'action item 2' } );
}
{
$form->process( {
'sched_count' => 2,
'schedules_2.id' => 2,
'schedules_2.note' => 'new appointment',
'schedules_2.count' => 2,
'schedules_2.tasks_1.id' => 2,
'schedules_2.tasks_1.detail' => 'new action item 1',
'schedules_2.tasks_2.id' => 3,
'schedules_2.tasks_2.detail' => 'new action item 2',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('Master')->find(1);
$form->model->update($row);
}
{
my $schedule = $schema->resultset('Schedule')->find(2);
is( $schedule->note, 'new appointment' );
my @add = $schedule->tasks->all;
is( scalar @add, 2 );
is( $add[0]->id, 2 );
is( $add[0]->detail, 'new action item 1' );
is( $add[1]->id, 3 );
is( $add[1]->detail, 'new action item 2' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/many_to_many_select_unselected.t 0000644 0001751 0001752 00000002513 13262760616 023752 0 ustar carl carl use strict;
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/update/many_to_many_select.yml');
my $schema = new_schema();
my $master = $schema->resultset('Master')-> create({ id => 1 });
my $band1;
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'John' } );
# band 1
$band1 = $u1->add_to_bands({ band => 'the beatles' });
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'Paul', } );
# band 2
$u2->add_to_bands({ band => 'wings' });
# band 3 - not used
$schema->resultset('Band')->create({ band => 'the kinks' });
# band 1
$u2->add_to_bands($band1);
}
# currently,
# user [2] => bands [2, 1]
{
$form->process( {
id => 2,
name => 'Paul McCartney',
# no bands - if you unselect all options,
# the browser doesn't submit that param at all
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $row = $schema->resultset('User')->find(2);
is( $row->name, 'Paul McCartney' );
my @bands = $row->bands->all;
is( scalar(@bands), 0 );
}
HTML-FormFu-Model-DBIC-2.03/t/update/might_have_create.t 0000644 0001751 0001752 00000002154 13262760616 021145 0 ustar carl carl use strict;
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/update/might_have.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
my $note_rs = $schema->resultset('Note');
# Fake submitted form
$form->process( {
"id" => 3,
"text_col" => 'a',
"note.note" => 'abc',
} );
{
# insert some entries we'll ignore, so our rels don't have same ids
# test id 1
my $t1 = $rs->new_result( { text_col => 'xxx' } );
$t1->insert;
# test id 2
my $t2 = $rs->new_result( { text_col => 'yyy' } );
$t2->insert;
# note id 1
my $n1 = $t2->new_related( 'note', { note => 'zzz' } );
$n1->insert;
# should get test id 3
my $master = $rs->new( { text_col => 'b' } );
$master->insert;
# no note, but next id 2
$form->model->update($master);
}
{
my $row = $rs->find(3);
is( $row->text_col, 'a' );
my $note = $row->note;
is( $note->id, 2 );
is( $note->note, 'abc' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_implicit.t 0000644 0001751 0001752 00000003425 13262760616 024237 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_many_repeatable_new_implicit.yml');
# config file doesn't set 'new_rows_max' so 'empty_rows' is used instead
my $schema = new_schema();
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'foo' } );
# address 1
$u1->create_related( 'addresses' => { address => 'somewhere' } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'nick', } );
# address 2
$u2->create_related( 'addresses', { address => 'home' } );
# address 3
$u2->create_related( 'addresses', { address => 'office' } );
}
{
$form->process( {
'id' => 2,
'name' => 'new nick',
'count' => 3,
'addresses_1.id' => 2,
'addresses_1.address' => 'new home',
'addresses_2.id' => 3,
'addresses_2.address' => 'new office',
'addresses_3.id' => '',
'addresses_3.address' => 'new address',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('User')->find(2);
$form->model->update($row);
}
{
my $user = $schema->resultset('User')->find(2);
is( $user->name, 'new nick' );
my @add = $user->addresses->all;
is( scalar @add, 3 );
is( $add[0]->id, 2 );
is( $add[0]->address, 'new home' );
is( $add[1]->id, 3 );
is( $add[1]->address, 'new office' );
is( $add[2]->id, 4 );
is( $add[2]->address, 'new address' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/belongs_to_lookup_table_combobox.t 0000644 0001751 0001752 00000003045 13262760616 024272 0 ustar carl carl use strict;
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
$rs->create( { id => 1 } );
$rs->create( { id => 2 } );
# types
my $type_rs = $schema->resultset('Type');
$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);
my $row = $rs->find(3);
is( $row->text_col, 'ccc');
is( $row->type->id, 4 );
is( $row->type->type, 'type 4' );
}
HTML-FormFu-Model-DBIC-2.03/t/update/has_many_repeatable_new_dependon.yml 0000644 0001751 0001752 00000000701 13262760616 024551 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Repeatable
nested_name: addresses
counter_name: count
model_config:
empty_rows: 2
elements:
- type: Hidden
name: id
constraints:
- type: DependOn
others: address
- type: Text
name: address
- type: Hidden
name: count
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/update/has_one_no_id.t 0000644 0001751 0001752 00000001770 13262760616 020276 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 4;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/update/has_one_no_id.yml');
my $schema = new_schema();
my $rs = $schema->resultset('Master');
# filler rows
{
# master 1
$rs->create( { text_col => 'xxx' } );
# master 2
my $m2 = $rs->create( { text_col => 'yyy' } );
# user 1
$m2->create_related( 'user', { name => 'zzz' } );
}
# rows we're going to use
{
# master 3
my $m3 = $rs->create( { text_col => 'b' } );
}
{
$form->process( {
"id" => 3,
"text_col" => 'a',
"user.name" => 'bar',
} );
ok( $form->submitted_and_valid );
my $row = $schema->resultset('Master')->find(3);
$form->model->update($row);
}
{
my $row = $schema->resultset('Master')->find(3);
is( $row->text_col, 'a' );
my $user = $row->user;
is( $user->id, 2 );
is( $user->name, 'bar' );
}
HTML-FormFu-Model-DBIC-2.03/t/00-report-prereqs.t 0000644 0001751 0001752 00000013426 13262760616 017440 0 ustar carl carl #!perl
use strict;
use warnings;
# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.027
use Test::More tests => 1;
use ExtUtils::MakeMaker;
use File::Spec;
# from $version::LAX
my $lax_version_re =
qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )?
|
(?:\.[0-9]+) (?:_[0-9]+)?
) | (?:
v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )?
|
(?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)?
)
)/x;
# hide optional CPAN::Meta modules from prereq scanner
# and check if they are available
my $cpan_meta = "CPAN::Meta";
my $cpan_meta_pre = "CPAN::Meta::Prereqs";
my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic
# Verify requirements?
my $DO_VERIFY_PREREQS = 1;
sub _max {
my $max = shift;
$max = ( $_ > $max ) ? $_ : $max for @_;
return $max;
}
sub _merge_prereqs {
my ($collector, $prereqs) = @_;
# CPAN::Meta::Prereqs object
if (ref $collector eq $cpan_meta_pre) {
return $collector->with_merged_prereqs(
CPAN::Meta::Prereqs->new( $prereqs )
);
}
# Raw hashrefs
for my $phase ( keys %$prereqs ) {
for my $type ( keys %{ $prereqs->{$phase} } ) {
for my $module ( keys %{ $prereqs->{$phase}{$type} } ) {
$collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module};
}
}
}
return $collector;
}
my @include = qw(
);
my @exclude = qw(
);
# Add static prereqs to the included modules list
my $static_prereqs = do './t/00-report-prereqs.dd';
# Merge all prereqs (either with ::Prereqs or a hashref)
my $full_prereqs = _merge_prereqs(
( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ),
$static_prereqs
);
# Add dynamic prereqs to the included modules list (if we can)
my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
my $cpan_meta_error;
if ( $source && $HAS_CPAN_META
&& (my $meta = eval { CPAN::Meta->load_file($source) } )
) {
$full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs);
}
else {
$cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source)
$source = 'static metadata';
}
my @full_reports;
my @dep_errors;
my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs;
# Add static includes into a fake section
for my $mod (@include) {
$req_hash->{other}{modules}{$mod} = 0;
}
for my $phase ( qw(configure build test runtime develop other) ) {
next unless $req_hash->{$phase};
next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING});
for my $type ( qw(requires recommends suggests conflicts modules) ) {
next unless $req_hash->{$phase}{$type};
my $title = ucfirst($phase).' '.ucfirst($type);
my @reports = [qw/Module Want Have/];
for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) {
next if $mod eq 'perl';
next if grep { $_ eq $mod } @exclude;
my $file = $mod;
$file =~ s{::}{/}g;
$file .= ".pm";
my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC;
my $want = $req_hash->{$phase}{$type}{$mod};
$want = "undef" unless defined $want;
$want = "any" if !$want && $want == 0;
my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";
if ($prefix) {
my $have = MM->parse_version( File::Spec->catfile($prefix, $file) );
$have = "undef" unless defined $have;
push @reports, [$mod, $want, $have];
if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) {
if ( $have !~ /\A$lax_version_re\z/ ) {
push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)";
}
elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) {
push @dep_errors, "$mod version '$have' is not in required range '$want'";
}
}
}
else {
push @reports, [$mod, $want, "missing"];
if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
push @dep_errors, "$mod is not installed ($req_string)";
}
}
}
if ( @reports ) {
push @full_reports, "=== $title ===\n\n";
my $ml = _max( map { length $_->[0] } @reports );
my $wl = _max( map { length $_->[1] } @reports );
my $hl = _max( map { length $_->[2] } @reports );
if ($type eq 'modules') {
splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports;
}
else {
splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl];
push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports;
}
push @full_reports, "\n";
}
}
}
if ( @full_reports ) {
diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
}
if ( $cpan_meta_error || @dep_errors ) {
diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n";
}
if ( $cpan_meta_error ) {
my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n";
}
if ( @dep_errors ) {
diag join("\n",
"\nThe following REQUIRED prerequisites were not satisfied:\n",
@dep_errors,
"\n"
);
}
pass;
# vim: ts=4 sts=4 sw=4 et:
HTML-FormFu-Model-DBIC-2.03/t/create/ 0000775 0001751 0001752 00000000000 13262760616 015303 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/create/basic.yml 0000644 0001751 0001752 00000001151 13262760616 017103 0 ustar carl carl ---
auto_fieldset: 1
model_config:
resultset: Master
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Password
name: password_col
- type: Checkbox
name: checkbox_col
value: foo
- type: Select
name: select_col
options:
- [1, one]
- [2, two]
- [3, three]
- type: Radio
name: radio_col
value: yes
- type: Radio
name: radio_col
value: no
- type: Radiogroup
name: radiogroup_col
values: [1, 2, 3]
- type: Text
name: date_col
- type: Text
name: unknown_col
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/create/basic.t 0000644 0001751 0001752 00000001616 13262760616 016553 0 ustar carl carl use strict;
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/create/basic.yml');
my $schema = new_schema();
# put schema on form stash
$form->stash->{schema} = $schema;
# Fake submitted form
$form->process( {
id => 1,
text_col => 'a',
password_col => 'b',
checkbox_col => 'foo',
select_col => '2',
radio_col => 'yes',
radiogroup_col => '3',
} );
{
# no resultset arg
$form->model->create;
}
{
my $row = $schema->resultset('Master')->find(1);
is( $row->text_col, 'a' );
is( $row->password_col, 'b' );
is( $row->checkbox_col, 'foo' );
is( $row->select_col, '2' );
is( $row->radio_col, 'yes' );
is( $row->radiogroup_col, '3' )
}
HTML-FormFu-Model-DBIC-2.03/t/lib/ 0000775 0001751 0001752 00000000000 13262760616 014606 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/ 0000775 0001751 0001752 00000000000 13262760616 016471 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/I18N.pm 0000644 0001751 0001752 00000000263 13262760616 017505 0 ustar carl carl package HTMLFormFu::I18N;
use strict;
use warnings;
use base 'Locale::Maketext';
*loc = \&localize;
sub localize {
my $self = shift;
return $self->maketext(@_);
}
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/MockContext.pm 0000644 0001751 0001752 00000000316 13262760616 021263 0 ustar carl carl package HTMLFormFu::MockContext;
use strict;
use warnings;
sub new {
my ( $class, $args ) = @_;
return bless $args, $class;
}
sub model {
my ( $self ) = @_;
return $self->{model}
}
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/I18N/ 0000775 0001751 0001752 00000000000 13262760616 017150 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/lib/HTMLFormFu/I18N/en.pm 0000644 0001751 0001752 00000000243 13262760616 020105 0 ustar carl carl package HTMLFormFu::I18N::en;
use strict;
use warnings;
use base qw( HTMLFormFu::I18N );
our %Lexicon = (
label_foo => 'Foo',
label_bar => 'Bar',
);
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/ 0000775 0001751 0001752 00000000000 13262760616 016314 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Band.pm 0000644 0001751 0001752 00000001116 13262760616 017513 0 ustar carl carl package MySchema::Band;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("band");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
manager => { data_type => "INTEGER", is_nullable => 1 },
band => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( manager => 'MySchema::Manager' );
__PACKAGE__->has_many( user_bands => 'MySchema::UserBand', 'band' );
__PACKAGE__->many_to_many( users => 'user_bands', 'user' );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/User.pm 0000644 0001751 0001752 00000002741 13262760616 017572 0 ustar carl carl package MySchema::User;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("user");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
master => { data_type => "INTEGER", is_nullable => 1 },
name => { data_type => "TEXT", is_nullable => 0 },
title => { data_type => "TEXT", is_nullable => 1 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( master => 'MySchema::Master', 'id' );
__PACKAGE__->has_many( addresses => 'MySchema::Address', 'user' );
__PACKAGE__->has_many( user_bands => 'MySchema::UserBand', 'user' );
__PACKAGE__->has_many( hasmanys => 'MySchema::HasMany', 'user' );
__PACKAGE__->many_to_many( bands => 'user_bands', 'band' );
__PACKAGE__->resultset_class('MySchemaRS::User');
sub fullname {
my $self = shift;
if (@_) {
my $fullname = shift;
my $match = qr/
(?: ( \w+ ) \s+ )?
( .* )
/x;
my ($title, $name) = $fullname =~ $match;
$self->set_column( 'title', $title );
$self->set_column( 'name', $name );
return $fullname;
}
my $title = $self->get_column('title');
my $name = $self->get_column('name');
return join ' ', grep {defined} $title, $name;
}
sub foo {
my ($self) = @_;
my $row = $self->find_or_new_related( 'hasmanys', { key => 'foo' } );
if ( @_ > 1 ) {
$row->update(@_);
}
return $row;
}
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Task.pm 0000644 0001751 0001752 00000001017 13262760616 017551 0 ustar carl carl package MySchema::Task;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("task");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
schedule => { data_type => "INTEGER", is_nullable => 0 },
deadline => { data_type => "DATETIME", is_nullable => 1 },
detail => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( schedule => 'MySchema::Schedule' );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/TwoNote.pm 0000644 0001751 0001752 00000000747 13262760616 020257 0 ustar carl carl package MySchema::TwoNote;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("two_note");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
two_note_id => { data_type => "INTEGER", is_nullable => 0 },
note => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("two_note_id");
__PACKAGE__->belongs_to( id => 'MySchema::Master', { id => 'id' } );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Type2.pm 0000644 0001751 0001752 00000000516 13262760616 017655 0 ustar carl carl package MySchema::Type2;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("type2");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
type => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Address.pm 0000644 0001751 0001752 00000001015 13262760616 020232 0 ustar carl carl package MySchema::Address;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("address");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
user => { data_type => "INTEGER", is_nullable => 0 },
my_label => { data_type => "TEXT", is_nullable => 1 },
address => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( user => 'MySchema::User' );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/ManagedBand.pm 0000644 0001751 0001752 00000001167 13262760616 020776 0 ustar carl carl package MySchema::ManagedBand;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("managed_band");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
manager_id => { data_type => "INTEGER", is_nullable => 0 },
band => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( manager => 'MySchema::Manager', 'manager_id' );
__PACKAGE__->has_many( user_bands => 'MySchema::UserBand', 'band' );
__PACKAGE__->many_to_many( users => 'user_bands', 'user' );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Manager.pm 0000644 0001751 0001752 00000000622 13262760616 020222 0 ustar carl carl package MySchema::Manager;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("manager");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
name => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many( bands => 'MySchema::Band', 'manager' );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Note.pm 0000644 0001751 0001752 00000000706 13262760616 017560 0 ustar carl carl package MySchema::Note;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("note");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
master => { data_type => "INTEGER", is_nullable => 0 },
note => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( master => 'MySchema::Master' );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Schedule.pm 0000644 0001751 0001752 00000001144 13262760616 020404 0 ustar carl carl package MySchema::Schedule;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ InflateColumn::DateTime Core /);
__PACKAGE__->table("schedule");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
master => { data_type => "INTEGER", is_nullable => 0 },
date => { data_type => "DATETIME", is_nullable => 0 },
note => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->belongs_to( master => 'MySchema::Master' );
__PACKAGE__->has_many( tasks => 'MySchema::Task', 'schedule' );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/UserBand.pm 0000644 0001751 0001752 00000001116 13262760616 020352 0 ustar carl carl package MySchema::UserBand;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("user_band");
__PACKAGE__->add_columns(
user => {
data_type => "INTEGER",
is_nullable => 0,
},
band => {
data_type => "INTEGER",
is_nullable => 0,
},
rating => {
data_type => "INTEGER",
is_nullable => 1,
}
);
__PACKAGE__->set_primary_key( "user", "band" );
__PACKAGE__->belongs_to( "user", "MySchema::User" );
__PACKAGE__->belongs_to( "band", "MySchema::Band" );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/HasMany.pm 0000644 0001751 0001752 00000000714 13262760616 020212 0 ustar carl carl package MySchema::HasMany;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("has_many");
__PACKAGE__->add_columns(
user => { data_type => "INTEGER", is_nullable => 0 },
key => { data_type => "TEXT", is_nullable => 0 },
value => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("user", "key");
__PACKAGE__->belongs_to( user => 'MySchema::User' );
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Master.pm 0000644 0001751 0001752 00000004552 13262760616 020111 0 ustar carl carl package MySchema::Master;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/
InflateColumn::DateTime Core
/);
__PACKAGE__->table("master");
__PACKAGE__->add_columns(
id => {
data_type => "INTEGER",
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 },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->might_have( note => 'MySchema::Note', 'master' );
__PACKAGE__->has_one( user => 'MySchema::User', 'master' );
__PACKAGE__->has_many( schedules => 'MySchema::Schedule', 'master' );
__PACKAGE__->belongs_to(
type => 'MySchema::Type',
{ 'foreign.id' => 'self.type_id' } );
__PACKAGE__->belongs_to(
type2 => 'MySchema::Type2',
{ 'foreign.id' => 'self.type2_id' } );
__PACKAGE__->inflate_column('array_col', { # {key=>val}
inflate => __PACKAGE__->inflate_column_list_comma,
deflate => __PACKAGE__->deflate_column_list_comma,
});
sub method_test {
my $self = shift;
if (@_) {
$self->text_col(@_);
}
return $self->text_col;
}
sub method_select_test {
my $self = shift;
if (@_) {
$self->select_col(@_);
}
return $self->select_col;
}
sub method_checkbox_test {
my $self = shift;
if (@_) {
$self->checkbox_col(@_);
}
return $self->checkbox_col;
}
sub inflate_column_list_comma {
sub {
[split(/,/, shift )];
}
}
sub deflate_column_list_comma {
sub {
join(',', @{(shift)} );
}
}
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema/Type.pm 0000644 0001751 0001752 00000000514 13262760616 017571 0 ustar carl carl package MySchema::Type;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("type");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER", is_nullable => 0 },
type => { data_type => "TEXT", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchema.pm 0000644 0001751 0001752 00000000156 13262760616 016652 0 ustar carl carl package MySchema;
use strict;
use warnings;
use base 'DBIx::Class::Schema';
__PACKAGE__->load_classes;
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/DBICTestLib.pm 0000644 0001751 0001752 00000001014 13262760616 017126 0 ustar carl carl package DBICTestLib;
use strict;
use warnings;
use DBI;
use base 'Exporter';
our @EXPORT_OK = qw/ new_schema /;
sub new_schema {
my $schema = MySchema->connect('dbi:SQLite:dbname=:memory:');
$schema->deploy;
$schema->resultset('Type')->create({ id => 1, type => 'foo' });
$schema->resultset('Type')->create({ id => 2, type => 'bar' });
$schema->resultset('Type2')->create({ id => 1, type => 'foo' });
$schema->resultset('Type2')->create({ id => 2, type => 'bar' });
return $schema;
}
1;
HTML-FormFu-Model-DBIC-2.03/t/lib/MySchemaRS/ 0000775 0001751 0001752 00000000000 13262760616 016561 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/lib/MySchemaRS/User.pm 0000644 0001751 0001752 00000001007 13262760616 020031 0 ustar carl carl package MySchemaRS::User;
use strict;
use warnings;
use base 'DBIx::Class::ResultSet';
sub is_name_available {
my ($self, $name, $row_id) = @_;
my $user = $self->find( {name => $name} );
return 0 if $user && $row_id && $user->id != $row_id; # found user with same name, and not user on stash
## do extra special-case testing
# my $name_reserved = $self->result_source->schema->resultset('NameReserved')->find( {name => $name} );
# return 0 if $name_reserved;
return 0 if $name eq 'xxx';
return 1;
}
1;
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/ 0000775 0001751 0001752 00000000000 13262760616 017736 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/t/options_from_model/many_to_many_select_restricted.t 0000644 0001751 0001752 00000003204 13262760616 026401 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 1;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use HTMLFormFu::MockContext;
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/many_to_many_select_restricted.yml');
my $schema = new_schema();
my $context = HTMLFormFu::MockContext->new( {
model => $schema->resultset('Band'),
} );
$form->stash( { context => $context } );
my $master = $schema->resultset('Master')->create({ id => 1 });
my $band1;
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'John' } );
# band 1
$band1 = $u1->add_to_bands( { band => 'the beatles', manager => 1 } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'Paul' } );
$u2->add_to_bands($band1);
# band 2
$u2->add_to_bands( { band => 'wings', manager => 1 } );
# band 3
$schema->resultset('Band')->create( { band => 'the kinks', manager => 2 } );
}
{
$form->process;
is_deeply(
$form->get_field('bands')->options,
[ { 'label_attributes' => {},
'value' => '1',
'label' => 'the beatles',
'attributes' => {},
'container_attributes' => {},
},
{ 'label_attributes' => {},
'value' => '2',
'label' => 'wings',
'attributes' => {},
'container_attributes' => {},
},
],
"Options set from the model"
);
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/constraint_autoset.t 0000644 0001751 0001752 00000002616 13262760616 024056 0 ustar carl carl 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/constraint_autoset.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $type_rs = $schema->resultset('Type');
my $type2_rs = $schema->resultset('Type2');
{
# types
$type_rs->delete;
$type_rs->create( { type => 'type 1' } );
$type_rs->create( { type => 'type 2' } );
$type_rs->create( { type => 'type 3' } );
$type2_rs->delete;
$type2_rs->create( { type => 'type 1' } );
$type2_rs->create( { type => 'type 2' } );
$type2_rs->create( { type => 'type 3' } );
}
$form->process({
type => 2,
type2_id => 4,
});
{
my $option = $form->get_field('type')->options;
ok( @$option == 3 );
is( $option->[0]->{label}, 'type 1' );
is( $option->[1]->{label}, 'type 2' );
is( $option->[2]->{label}, 'type 3' );
}
{
my $option = $form->get_field('type2_id')->options;
ok( @$option == 3 );
is( $option->[0]->{label}, 'type 1' );
is( $option->[1]->{label}, 'type 2' );
is( $option->[2]->{label}, 'type 3' );
}
# ensure the options are set in time for the AutoSet constraint to work
ok( $form->valid('type') );
ok( !$form->valid('type2_id') );
is_deeply(
$form->params,
{
type => 2,
}
);
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_config_zero_combobox.yml 0000644 0001751 0001752 00000000325 13262760616 027066 0 ustar carl carl ---
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
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_complex.t 0000644 0001751 0001752 00000002235 13262760616 026065 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 4;
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.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' });
$m1->create_related( 'user', { name => 'a' } );
$m1->create_related( 'user', { name => 'b' } );
$m1->create_related( 'user', { name => 'c' } );
}
{
my $m2 = $master_rs->create({ text_col => 'bar' });
$m2->create_related( 'user', { name => 'd' } );
$m2->create_related( 'user', { name => 'e' } );
$m2->create_related( 'user', { name => 'f' } );
$m2->create_related( 'user', { name => 'g' } );
}
# master_id contains a complex condition
$form->stash->{master_id} = {'!=' => '2' };
$form->process;
{
my $option = $form->get_field('user')->options;
ok( @$option == 3 );
is( $option->[0]->{label}, 'a' );
is( $option->[1]->{label}, 'b' );
is( $option->[2]->{label}, 'c' );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_localize_label.yml 0000644 0001751 0001752 00000000317 13262760616 025634 0 ustar carl carl ---
auto_fieldset: 1
localize_class: 'HTMLFormFu::I18N'
elements:
- type: Hidden
name: id
- type: Select
name: type
model_config:
localize_label: 1
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to.t 0000644 0001751 0001752 00000002222 13262760616 022252 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 8;
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.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $type_rs = $schema->resultset('Type');
my $type2_rs = $schema->resultset('Type2');
{
# types
$type_rs->delete;
$type_rs->create( { type => 'type 1' } );
$type_rs->create( { type => 'type 2' } );
$type_rs->create( { type => 'type 3' } );
$type2_rs->delete;
$type2_rs->create( { type => 'type 1' } );
$type2_rs->create( { type => 'type 2' } );
$type2_rs->create( { type => 'type 3' } );
}
$form->process;
{
my $option = $form->get_field('type')->options;
ok( @$option == 3 );
is( $option->[0]->{label}, 'type 1' );
is( $option->[1]->{label}, 'type 2' );
is( $option->[2]->{label}, 'type 3' );
}
{
my $option = $form->get_field('type2_id')->options;
ok( @$option == 3 );
is( $option->[0]->{label}, 'type 1' );
is( $option->[1]->{label}, 'type 2' );
is( $option->[2]->{label}, 'type 3' );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_combobox.yml 0000644 0001751 0001752 00000000240 13262760616 026556 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: ComboBox
name: user
model_config:
resultset: User
condition_from_stash:
master: master_id
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_combobox_complex.t 0000644 0001751 0001752 00000002311 13262760616 027750 0 ustar carl carl 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' });
$m1->create_related( 'user', { name => 'a' } );
$m1->create_related( 'user', { name => 'b' } );
$m1->create_related( 'user', { name => 'c' } );
}
{
my $m2 = $master_rs->create({ text_col => 'bar' });
$m2->create_related( 'user', { name => 'd' } );
$m2->create_related( 'user', { name => 'e' } );
$m2->create_related( 'user', { name => 'f' } );
$m2->create_related( 'user', { name => 'g' } );
}
# master_id contains complex condition
$form->stash->{master_id} = {'!=' => '2' };
$form->process;
{
my $option = $form->get_field('user')->options;
ok( @$option == 4 );
is( $option->[0]->{label}, '' );
is( $option->[1]->{label}, 'a' );
is( $option->[2]->{label}, 'b' );
is( $option->[3]->{label}, 'c' );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/enum_select.yml 0000644 0001751 0001752 00000000417 13262760616 022764 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Select
name: enum_col
model_config:
options_from_model: 1
resultset: Master
constraint:
- AutoSet
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_config_zero_combobox.t 0000644 0001751 0001752 00000001632 13262760616 026532 0 ustar carl carl 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');
{
# types
$type_rs->delete;
$type_rs->create( { type => 'type 1' } );
$type_rs->create( { type => 'type 2' } );
$type_rs->create( { type => 'type 3' } );
$type2_rs->delete;
$type2_rs->create( { type => 'type 1' } );
$type2_rs->create( { type => 'type 2' } );
$type2_rs->create( { type => 'type 3' } );
}
$form->process;
# options() isn't set, because we explicitly set options_from_model to 0
{
my $option = $form->get_field('type')->options;
is( scalar @$option, 0 );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/enum_select.t 0000644 0001751 0001752 00000001501 13262760616 022421 0 ustar carl carl use strict;
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/options_from_model/enum_select.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $master_rs = $schema->resultset('Master');
$form->process;
{
my $option = $form->get_field('enum_col')->options;
is( scalar( @$option ), 3 );
is( $option->[0]->{label}, 'a' );
is( $option->[1]->{label}, 'b' );
is( $option->[2]->{label}, 'c' );
}
# ensure the options are set in time for the AutoSet constraint to work
{
$form->process({
enum_col => 'a',
});
ok( $form->valid('enum_col') );
}
{
$form->process({
enum_col => 'd',
});
ok( ! $form->valid('enum_col') );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_combobox.t 0000644 0001751 0001752 00000003242 13262760616 026225 0 ustar carl carl 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' });
$m1->create_related( 'user', { name => 'a' } );
$m1->create_related( 'user', { name => 'b' } );
$m1->create_related( 'user', { name => 'c' } );
}
{
my $m2 = $master_rs->create({ text_col => 'bar' });
$m2->create_related( 'user', { name => 'd' } );
$m2->create_related( 'user', { name => 'e' } );
$m2->create_related( 'user', { name => 'f' } );
$m2->create_related( 'user', { name => 'g' } );
# master_id contains unique id
$form->stash->{master_id} = $m2->id;
}
$form->process;
{
my $option = $form->get_field('user')->options;
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}, '' );
is( $option->[1]->{label}, 'a' );
is( $option->[2]->{label}, 'b' );
is( $option->[3]->{label}, 'c' );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/has_many_repeatable_select.yml 0000644 0001751 0001752 00000000620 13262760616 025777 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Hidden
name: count
- type: Repeatable
nested_name: bands
counter_name: count
elements:
- type: Hidden
name: id
- name: band
- type: Checkboxgroup
name: users
model_config:
resultset: User
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_expand.yml 0000644 0001751 0001752 00000000271 13262760616 026231 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Select
name: user
model_config:
resultset: User
condition_from_stash:
master: foo.bar.0
expand_stash_dots: 1
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/many_to_many_select.yml 0000644 0001751 0001752 00000000327 13262760616 024512 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Select
name: bands
multiple: 1
model_config:
model: Bands
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_localize_label.t 0000644 0001751 0001752 00000001235 13262760616 025276 0 ustar carl carl use strict;
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/options_from_model/belongs_to_localize_label.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $type_rs = $schema->resultset('Type');
{
# types
$type_rs->delete;
$type_rs->create( { type => 'label_foo' } );
$type_rs->create( { type => 'label_bar' } );
}
$form->process;
{
my $option = $form->get_field('type')->options;
ok( @$option == 2 );
is( $option->[0]->{label}, 'Foo' );
is( $option->[1]->{label}, 'Bar' );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/constraint_autoset.yml 0000644 0001751 0001752 00000000541 13262760616 024407 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Select
name: type
model_config:
options_from_model: 1
constraint:
- AutoSet
- type: Select
name: type2_id
model_config:
resultset: Type2
constraint:
- AutoSet
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/many_to_many_select.t 0000644 0001751 0001752 00000003516 13262760616 024157 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 1;
use HTML::FormFu;
use lib 't/lib';
use DBICTestLib 'new_schema';
use HTMLFormFu::MockContext;
use MySchema;
my $form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/many_to_many_select.yml');
my $schema = new_schema();
my $context = HTMLFormFu::MockContext->new( {
model => $schema->resultset('Band'),
} );
$form->stash( { context => $context } );
my $master = $schema->resultset('Master')->create({ id => 1 });
my $band1;
# filler rows
{
# user 1
my $u1 = $master->create_related( 'user', { name => 'John' } );
# band 1
$band1 = $u1->add_to_bands( { band => 'the beatles' } );
}
# rows we're going to use
{
# user 2
my $u2 = $master->create_related( 'user', { name => 'Paul' } );
$u2->add_to_bands($band1);
# band 2
$u2->add_to_bands( { band => 'wings' } );
# band 3
$schema->resultset('Band')->create( { band => 'the kinks' } );
}
{
$form->process;
is_deeply(
$form->get_field('bands')->options,
[ { 'label_attributes' => {},
'value' => '1',
'label' => 'the beatles',
'attributes' => {},
'container_attributes' => {},
},
{ 'label_attributes' => {},
'value' => '2',
'label' => 'wings',
'attributes' => {},
'container_attributes' => {},
},
{ 'label_attributes' => {},
'value' => '3',
'label' => 'the kinks',
'attributes' => {},
'container_attributes' => {},
},
],
"Options set from the model"
);
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/has_many_repeatable_select.t 0000644 0001751 0001752 00000006437 13262760616 025455 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 34;
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/has_many_repeatable_select.yml');
my $schema = new_schema();
$form->stash( { schema => $schema } );
my $master = $schema->resultset('Master')->create({ id => 1 });
# filler rows
{
# user 1, 2
$master->create_related( 'user', { name => 'user 1' } );
$master->create_related( 'user', { name => 'user 2' } );
}
# rows we're going to use
{
# manager 1
my $manager = $schema->resultset('Manager')->create({ name => 'manager 1' });
# band 1, 2
my $band1 = $manager->create_related( 'bands', { band => 'band 1' } );
my $band2 = $manager->create_related( 'bands', { band => 'band 2' } );
# user 3, 4
$band1->add_to_users({ name => 'user 3', master => $manager->id });
$band1->add_to_users({ name => 'user 4', master => $manager->id });
# user 5
$band2->add_to_users({ name => 'user 5', master => $manager->id });
}
{
$form->process;
my $manager = $schema->resultset('Manager')->find(1);
$form->model->default_values( $manager );
is( $form->get_field('id')->default, '1' );
is( $form->get_field('name')->default, 'manager 1' );
is( $form->get_field('count')->default, '2' );
my $bands_repeatable = $form->get_all_element({ nested_name => 'bands' });
my @bands = @{ $bands_repeatable->get_elements };
is( scalar @bands, 2 );
# band 1
{
is( $bands[0]->nested_name, 'bands_1' );
is( $bands[0]->get_field('id')->default, '1' );
is( $bands[0]->get_field('band')->default, 'band 1' );
# user 3
my $select = $bands[0]->get_field('users');
is_deeply( $select->default, [3, 4] );
is( scalar @{ $select->options }, 5 );
is( $select->options->[0]->{value}, '1' );
is( $select->options->[0]->{label}, 'user 1' );
is( $select->options->[1]->{value}, '2' );
is( $select->options->[1]->{label}, 'user 2' );
is( $select->options->[2]->{value}, '3' );
is( $select->options->[2]->{label}, 'user 3' );
is( $select->options->[3]->{value}, '4' );
is( $select->options->[3]->{label}, 'user 4' );
is( $select->options->[4]->{value}, '5' );
is( $select->options->[4]->{label}, 'user 5' );
}
# band 2
{
is( $bands[1]->nested_name, 'bands_2' );
is( $bands[1]->get_field('id')->default, '2' );
is( $bands[1]->get_field('band')->default, 'band 2' );
# user 3
my $select = $bands[1]->get_field('users');
is_deeply( $select->default, [5] );
is( scalar @{ $select->options }, 5 );
is( $select->options->[0]->{value}, '1' );
is( $select->options->[0]->{label}, 'user 1' );
is( $select->options->[1]->{value}, '2' );
is( $select->options->[1]->{label}, 'user 2' );
is( $select->options->[2]->{value}, '3' );
is( $select->options->[2]->{label}, 'user 3' );
is( $select->options->[3]->{value}, '4' );
is( $select->options->[3]->{label}, 'user 4' );
is( $select->options->[4]->{value}, '5' );
is( $select->options->[4]->{label}, 'user 5' );
}
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash.t 0000644 0001751 0001752 00000003042 13262760616 024333 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 9;
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.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' });
$m1->create_related( 'user', { name => 'a' } );
$m1->create_related( 'user', { name => 'b' } );
$m1->create_related( 'user', { name => 'c' } );
}
{
my $m2 = $master_rs->create({ text_col => 'bar' });
$m2->create_related( 'user', { name => 'd' } );
$m2->create_related( 'user', { name => 'e' } );
$m2->create_related( 'user', { name => 'f' } );
$m2->create_related( 'user', { name => 'g' } );
$form->stash->{master_id} = $m2->id;
}
$form->process;
{
my $option = $form->get_field('user')->options;
ok( @$option == 4 );
is( $option->[0]->{label}, 'd' );
is( $option->[1]->{label}, 'e' );
is( $option->[2]->{label}, 'f' );
is( $option->[3]->{label}, 'g' );
}
$form = HTML::FormFu->new;
$form->load_config_file('t/options_from_model/condition_from_stash.yml');
$form->stash->{schema} = $schema;
$form->stash->{master_id} = {'!=' => '2' };
$form->process;
{
my $option = $form->get_field('user')->options;
ok( @$option == 3 );
is( $option->[0]->{label}, 'a' );
is( $option->[1]->{label}, 'b' );
is( $option->[2]->{label}, 'c' );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_combobox.t 0000644 0001751 0001752 00000002502 13262760616 024143 0 ustar carl carl 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');
{
# types
$type_rs->delete;
$type_rs->create( { type => 'type 1' } );
$type_rs->create( { type => 'type 2' } );
$type_rs->create( { type => 'type 3' } );
$type2_rs->delete;
$type2_rs->create( { type => 'type 1' } );
$type2_rs->create( { type => 'type 2' } );
$type2_rs->create( { type => 'type 3' } );
}
$form->process;
is(
$form->get_field('type'),
qq{
}
);
is(
$form->get_field('type2_id'),
qq{
}
);
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to.yml 0000644 0001751 0001752 00000000425 13262760616 022613 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Select
name: type
model_config:
aaa : aaa
- type: Select
name: type2_id
model_config:
resultset: Type2
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash.yml 0000644 0001751 0001752 00000000236 13262760616 024673 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Select
name: user
model_config:
resultset: User
condition_from_stash:
master: master_id
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_config_zero.t 0000644 0001751 0001752 00000001621 13262760616 024640 0 ustar carl carl 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.yml');
my $schema = new_schema();
$form->stash->{schema} = $schema;
my $type_rs = $schema->resultset('Type');
my $type2_rs = $schema->resultset('Type2');
{
# types
$type_rs->delete;
$type_rs->create( { type => 'type 1' } );
$type_rs->create( { type => 'type 2' } );
$type_rs->create( { type => 'type 3' } );
$type2_rs->delete;
$type2_rs->create( { type => 'type 1' } );
$type2_rs->create( { type => 'type 2' } );
$type2_rs->create( { type => 'type 3' } );
}
$form->process;
# options() isn't set, because we explicitly set options_from_model to 0
{
my $option = $form->get_field('type')->options;
is( scalar @$option, 0 );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_combobox.yml 0000644 0001751 0001752 00000000431 13262760616 024500 0 ustar carl carl ---
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
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/condition_from_stash_expand.t 0000644 0001751 0001752 00000002302 13262760616 025670 0 ustar carl carl use strict;
use warnings;
use Test::More tests => 4;
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.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' });
$m1->create_related( 'user', { name => 'a' } );
$m1->create_related( 'user', { name => 'b' } );
$m1->create_related( 'user', { name => 'c' } );
}
{
my $m2 = $master_rs->create({ text_col => 'bar' });
$m2->create_related( 'user', { name => 'd' } );
$m2->create_related( 'user', { name => 'e' } );
$m2->create_related( 'user', { name => 'f' } );
$m2->create_related( 'user', { name => 'g' } );
$form->stash->{foo}{bar}[0] = $m2->id;
}
$form->stash->{schema} = $schema;
$form->stash->{master_id} = {'!=' => '2' };
$form->process;
{
my $option = $form->get_field('user')->options;
ok( @$option == 3 );
is( $option->[0]->{label}, 'a' );
is( $option->[1]->{label}, 'b' );
is( $option->[2]->{label}, 'c' );
}
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/belongs_to_config_zero.yml 0000644 0001751 0001752 00000000323 13262760616 025174 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: text_col
- type: Select
name: type
model_config:
options_from_model: 0
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/t/options_from_model/many_to_many_select_restricted.yml 0000644 0001751 0001752 00000000373 13262760616 026743 0 ustar carl carl ---
auto_fieldset: 1
elements:
- type: Hidden
name: id
- type: Text
name: name
- type: Select
name: bands
multiple: 1
model_config:
model: Bands
condition:
manager: 1
- type: Submit
name: submit
HTML-FormFu-Model-DBIC-2.03/Changes 0000644 0001751 0001752 00000011473 13262760616 015074 0 ustar carl carl 2.03 2018-04-09 21:56:26+00:00 UTC
- New 'expand_stash_dots' config option
- remove bundled/renamed MooseX::Attribute::Chained and depend on the
fixed version
2.02 2016-06-24
- documentation fixes
- build and packaging tweaks, including travis CI config, additional
author tests, packaging etc
2.00 2014-05-05
- switch from MooseX::Attribute::Chained to MooseX::Attribute::FormFuChained
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.
- Require HTML-FormFu v0.09010 due to internals used by
Constraint::DBIC::Unique
0.09000 2011-03-29
- Updated to work with HTML-FormFu 0.09000
- condition_from_stash now accepts hash from stash, but not from config.
0.08002 2010-09-22
- Incompatible Change: removed all previously deprecated methods.
- Fix: Was trying to pass undef to NOT NULL columns - changed check from
( $is_nullable || ... ) to ( $is_nullable && ... )
appears to have been unintentionally changed in svn r93 when the code
was a part of DBIx::Class::HTML::FormFu.
- many-to-many handling with restricting condition tests and code
to prevent deleting outside of restriction in update code.
- New 'others' option for Constraint::DBIC::Unique.
- Constraint::DBIC::Unique tests added.
0.06000 2009-12-10
- Test suite now uses in-memory SQLite database, so tests can be run in
parallel.
- many-to-many Checkboxgroup tests.
0.05003 2009-11-25
- New 'link_values' and 'additive' options for multi-value fields for
many-to-many relationships.
- Doc updates.
0.05002 2009-07-06
- Remove prerequisite Test::MockObject - it uses UNIVERSAL::isa which
was causing test failures.
0.05001 2009-07-03
- Fix delete_if_true to work inside a surrounding block.
- Made DBIC deletes conditional on row being in_storage.
- Bump DBIx::Class prerequisite to 0.08106, when it switched from using
DateTime::Format::MySQL to DateTime::Format::SQLite.
0.05000 2009-05-26
- Fix update() "primary key and the foreign key may not be the same column"
errors.
- options_from_model() 'label_col' works again with non-column accessors.
0.04003 2009-05-10
- Bumped prerequisite HTML-FormFu to 0.04002
0.04002 2009-05-08
- New "empty_rows" setting - replaces now deprecated "new_empty_row".
- New "new_rows_max" setting - replaces now deprecated "new_empty_row_multi".
- Previously, the field named in "new_empty_row" was used to determine
whether to insert a new row. - Now we simply insert a new row if any
field within the Repeatable block has a submitted value.
- New 'read_only' model_config option.
- New 'ignore_if_empty' model_config option.
- Support nested Repeatable elements.
0.04000 2009-04-22
- New "empty_rows" setting - replaces now deprecated "new_empty_row".
- New "new_rows_max" setting - replaces now deprecated "new_empty_row_multi".
- Previously, the field named in "new_empty_row" was used to determine
whether to insert a new row. - Now we simply insert a new row if any
field within the Repeatable block has a submitted value.
0.03007 2008-12-08
- 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
- New {label} setting.
- New {new_empty_row_multi} setting.
- Allow {nested_base} on non-column, non-rel methods.
- Bugfix: RT#35861 - not all non-field elements have a nested_name() method.
- Bugfix: use new_related() instead of create_related() before setting
column values, to ensure we don't die on NOT NULL columns.
0.03000 2008-06-19
- First CPAN release
- HTML::FormFu::Model::DBIC moved out of HTML::FormFu distribution
HTML-FormFu-Model-DBIC-2.03/META.yml 0000644 0001751 0001752 00000025412 13262760616 015050 0 ustar carl carl ---
abstract: 'Integrate HTML::FormFu with DBIx::Class'
author:
- 'Carl Franks '
build_requires:
DateTime::Format::SQLite: '0'
ExtUtils::MakeMaker: '0'
File::Spec: '0'
Locale::Maketext: '0'
SQL::Translator: '0.11016'
Test::More: '0.99'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.011, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: HTML-FormFu-Model-DBIC
no_index:
directory:
- eg
- examples
- inc
- share
- t
- xt
provides:
HTML::FormFu::Constraint::DBIC::Unique:
file: lib/HTML/FormFu/Constraint/DBIC/Unique.pm
version: '2.03'
HTML::FormFu::Model::DBIC:
file: lib/HTML/FormFu/Model/DBIC.pm
version: '2.03'
requires:
DBD::SQLite: '0'
DBIx::Class: '0.08108'
HTML::FormFu: '2.00'
List::MoreUtils: '0'
MooseX::Attribute::Chained: v1.0.2
Storable: '0'
Task::Weaken: '0'
perl: '5.008001'
resources:
homepage: https://github.com/FormFu/HTML-FormFu-Model-DBIC
repository: https://github.com/FormFu/HTML-FormFu-Model-DBIC.git
version: '2.03'
x_Dist_Zilla:
perl:
version: '5.014004'
plugins:
-
class: Dist::Zilla::Plugin::Prereqs
config:
Dist::Zilla::Plugin::Prereqs:
phase: runtime
type: requires
name: Prereqs
version: '6.011'
-
class: Dist::Zilla::Plugin::Prereqs
config:
Dist::Zilla::Plugin::Prereqs:
phase: test
type: requires
name: TestRequires
version: '6.011'
-
class: Dist::Zilla::Plugin::Prereqs
config:
Dist::Zilla::Plugin::Prereqs:
phase: develop
type: requires
name: DevelopRequires
version: '6.011'
-
class: Dist::Zilla::Plugin::Test::Perl::Critic
name: Test::Perl::Critic
version: '3.001'
-
class: Dist::Zilla::Plugin::MetaTests
name: MetaTests
version: '6.011'
-
class: Dist::Zilla::Plugin::OurPkgVersion
name: OurPkgVersion
version: '0.12'
-
class: Dist::Zilla::Plugin::PodVersion
name: PodVersion
version: '6.011'
-
class: Dist::Zilla::Plugin::Test::Kwalitee
config:
Dist::Zilla::Plugin::Test::Kwalitee:
filename: xt/release/kwalitee.t
skiptest: []
name: Test::Kwalitee
version: '2.12'
-
class: Dist::Zilla::Plugin::Test::EOL
config:
Dist::Zilla::Plugin::Test::EOL:
filename: xt/author/eol.t
finder:
- ':InstallModules'
trailing_whitespace: 1
name: Test::EOL
version: '0.19'
-
class: Dist::Zilla::Plugin::Test::PAUSE::Permissions
name: Test::PAUSE::Permissions
version: '0.003'
-
class: Dist::Zilla::Plugin::GithubMeta
name: GithubMeta
version: '0.54'
-
class: Dist::Zilla::Plugin::NextRelease
name: NextRelease
version: '6.011'
-
class: Dist::Zilla::Plugin::Git::GatherDir
config:
Dist::Zilla::Plugin::GatherDir:
exclude_filename: []
exclude_match: []
follow_symlinks: 0
include_dotfiles: 0
prefix: ''
prune_directory: []
root: .
Dist::Zilla::Plugin::Git::GatherDir:
include_untracked: 0
name: Git::GatherDir
version: '2.043'
-
class: Dist::Zilla::Plugin::Git::NextVersion
config:
Dist::Zilla::Plugin::Git::NextVersion:
first_version: '0.001'
version_by_branch: 0
version_regexp: (?^:^v(.+)$)
Dist::Zilla::Role::Git::Repo:
git_version: 1.9.1
repo_root: .
name: Git::NextVersion
version: '2.043'
-
class: Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch
config:
Dist::Zilla::Role::Git::Repo:
git_version: 1.9.1
repo_root: .
name: Git::CheckFor::CorrectBranch
version: '0.014'
-
class: Dist::Zilla::Plugin::Git::Remote::Check
name: Git::Remote::Check
version: 0.1.2
-
class: Dist::Zilla::Plugin::PruneCruft
name: '@Starter/PruneCruft'
version: '6.011'
-
class: Dist::Zilla::Plugin::ManifestSkip
name: '@Starter/ManifestSkip'
version: '6.011'
-
class: Dist::Zilla::Plugin::MetaConfig
name: '@Starter/MetaConfig'
version: '6.011'
-
class: Dist::Zilla::Plugin::MetaProvides::Package
config:
Dist::Zilla::Plugin::MetaProvides::Package:
finder_objects:
-
class: Dist::Zilla::Plugin::FinderCode
name: '@Starter/MetaProvides::Package/AUTOVIV/:InstallModulesPM'
version: '6.011'
include_underscores: 0
Dist::Zilla::Role::MetaProvider::Provider:
$Dist::Zilla::Role::MetaProvider::Provider::VERSION: '2.002004'
inherit_missing: '1'
inherit_version: '1'
meta_noindex: '1'
Dist::Zilla::Role::ModuleMetadata:
Module::Metadata: '1.000033'
version: '0.005'
name: '@Starter/MetaProvides::Package'
version: '2.004003'
-
class: Dist::Zilla::Plugin::MetaNoIndex
name: '@Starter/MetaNoIndex'
version: '6.011'
-
class: Dist::Zilla::Plugin::MetaYAML
name: '@Starter/MetaYAML'
version: '6.011'
-
class: Dist::Zilla::Plugin::MetaJSON
name: '@Starter/MetaJSON'
version: '6.011'
-
class: Dist::Zilla::Plugin::License
name: '@Starter/License'
version: '6.011'
-
class: Dist::Zilla::Plugin::ReadmeAnyFromPod
config:
Dist::Zilla::Role::FileWatcher:
version: '0.006'
name: '@Starter/ReadmeAnyFromPod'
version: '0.163250'
-
class: Dist::Zilla::Plugin::ExecDir
name: '@Starter/ExecDir'
version: '6.011'
-
class: Dist::Zilla::Plugin::ShareDir
name: '@Starter/ShareDir'
version: '6.011'
-
class: Dist::Zilla::Plugin::PodSyntaxTests
name: '@Starter/PodSyntaxTests'
version: '6.011'
-
class: Dist::Zilla::Plugin::Test::ReportPrereqs
name: '@Starter/Test::ReportPrereqs'
version: '0.027'
-
class: Dist::Zilla::Plugin::Test::Compile
config:
Dist::Zilla::Plugin::Test::Compile:
bail_out_on_fail: '0'
fail_on_warning: author
fake_home: 0
filename: xt/author/00-compile.t
module_finder:
- ':InstallModules'
needs_display: 0
phase: develop
script_finder:
- ':PerlExecFiles'
skips: []
switch: []
name: '@Starter/Test::Compile'
version: '2.058'
-
class: Dist::Zilla::Plugin::MakeMaker
config:
Dist::Zilla::Role::TestRunner:
default_jobs: 1
name: '@Starter/MakeMaker'
version: '6.011'
-
class: Dist::Zilla::Plugin::Manifest
name: '@Starter/Manifest'
version: '6.011'
-
class: Dist::Zilla::Plugin::TestRelease
name: '@Starter/TestRelease'
version: '6.011'
-
class: Dist::Zilla::Plugin::RunExtraTests
config:
Dist::Zilla::Role::TestRunner:
default_jobs: 1
name: '@Starter/RunExtraTests'
version: '0.029'
-
class: Dist::Zilla::Plugin::ConfirmRelease
name: '@Starter/ConfirmRelease'
version: '6.011'
-
class: Dist::Zilla::Plugin::UploadToCPAN
name: '@Starter/UploadToCPAN'
version: '6.011'
-
class: Dist::Zilla::Plugin::ReadmeAnyFromPod
config:
Dist::Zilla::Role::FileWatcher:
version: '0.006'
name: Pod_Readme
version: '0.163250'
-
class: Dist::Zilla::Plugin::Git::Check
config:
Dist::Zilla::Plugin::Git::Check:
untracked_files: die
Dist::Zilla::Role::Git::DirtyFiles:
allow_dirty:
- Changes
- README.pod
- dist.ini
allow_dirty_match: []
changelog: Changes
Dist::Zilla::Role::Git::Repo:
git_version: 1.9.1
repo_root: .
name: '@Git/Check'
version: '2.043'
-
class: Dist::Zilla::Plugin::Git::Commit
config:
Dist::Zilla::Plugin::Git::Commit:
add_files_in: []
commit_msg: 'v%v%t - %d%n%n%c'
Dist::Zilla::Role::Git::DirtyFiles:
allow_dirty:
- Changes
- README.pod
- dist.ini
allow_dirty_match: []
changelog: Changes
Dist::Zilla::Role::Git::Repo:
git_version: 1.9.1
repo_root: .
Dist::Zilla::Role::Git::StringFormatter:
time_zone: local
name: '@Git/Commit'
version: '2.043'
-
class: Dist::Zilla::Plugin::Git::Tag
config:
Dist::Zilla::Plugin::Git::Tag:
branch: ~
changelog: Changes
signed: 0
tag: v2.03
tag_format: v%v%t
tag_message: 'v%v%t - %d'
Dist::Zilla::Role::Git::Repo:
git_version: 1.9.1
repo_root: .
Dist::Zilla::Role::Git::StringFormatter:
time_zone: local
name: '@Git/Tag'
version: '2.043'
-
class: Dist::Zilla::Plugin::Git::Push
config:
Dist::Zilla::Plugin::Git::Push:
push_to:
- origin
remotes_must_exist: 1
Dist::Zilla::Role::Git::Repo:
git_version: 1.9.1
repo_root: .
name: '@Git/Push'
version: '2.043'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':InstallModules'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':IncModules'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':TestFiles'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':ExtraTestFiles'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':ExecFiles'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':PerlExecFiles'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':ShareFiles'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':MainModule'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':AllFiles'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: ':NoFiles'
version: '6.011'
-
class: Dist::Zilla::Plugin::FinderCode
name: '@Starter/MetaProvides::Package/AUTOVIV/:InstallModulesPM'
version: '6.011'
zilla:
class: Dist::Zilla::Dist::Builder
config:
is_trial: '0'
version: '6.011'
x_serialization_backend: 'YAML::Tiny version 1.73'
HTML-FormFu-Model-DBIC-2.03/README 0000644 0001751 0001752 00000052547 13262760616 014470 0 ustar carl carl NAME
HTML::FormFu::Model::DBIC - Integrate HTML::FormFu with DBIx::Class
VERSION
version 2.03
SYNOPSIS
Example of typical use in a Catalyst controller:
sub edit : Chained {
my ( $self, $c ) = @_;
my $form = $c->stash->{form};
my $book = $c->stash->{book};
if ( $form->submitted_and_valid ) {
# update dbic row with submitted values from form
$form->model->update( $book );
$c->response->redirect( $c->uri_for('view', $book->id) );
return;
}
elsif ( !$form->submitted ) {
# use dbic row to set form's default values
$form->model->default_values( $book );
}
return;
}
SETUP
For the form object to be able to access your DBIx::Class schema, it
needs to be placed on the form stash, with the name schema.
This is easy if you're using Catalyst-Controller-HTML-FormFu, as you
can set this up to happen in your Catalyst app's config file.
For example, if your model is named MyApp::Model::Corp, you would set
this (in Config::General format):
schema Corp
Or if your app's config file is in YAML format:
'Controller::HTML::FormFu':
model_stash:
schema: Corp
METHODS
default_values
Arguments: $dbic_row, [\%config]
Return Value: $form
$form->model->default_values( $dbic_row );
Set a form's default values from the database, to allow a user to edit
them.
update
Arguments: [$dbic_row], [\%config]
Return Value: $dbic_row
$form->model->update( $dbic_row );
Update the database with the submitted form values.
create
Arguments: [\%config]
Return Value: $dbic_row
my $dbic_row = $form->model->create( {resultset => 'Book'} );
Like "update", but doesn't require a $dbic_row argument.
You need to ensure the DBIC schema is available on the form stash - see
"SYNOPSIS" for an example config.
The resultset must be set either in the method arguments, or the form
or block's model_config.
An example of setting the ResultSet name on a Form:
---
model_config:
resultset: FooTable
elements:
# [snip]
options_from_model
Populates a multi-valued field with values from the database.
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
BUILDING FORMS
single table
To edit the values in a row with no related rows, the field names
simply have to correspond to the database column names.
For the following DBIx::Class schema:
package MySchema::Book;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("book");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER" },
title => { data_type => "TEXT" },
author => { data_type => "TEXT" },
blurb => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("id");
1;
A suitable form for this might be:
elements:
- type: Text
name: title
- type: Text
name: author
- type: Textarea
name: blurb
might_have and has_one relationships
Set field values from a related row with a might_have or has_one
relationship by placing the fields within a Block (or any element that
inherits from Block, such as Fieldset) with its "nested_name" in
HTML::FormFu set to the relationship name.
For the following DBIx::Class schemas:
package MySchema::Book;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("book");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER" },
title => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->might_have( review => 'MySchema::Review', 'book' );
1;
package MySchema::Review;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("review");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER" },
book => { data_type => "INTEGER", is_nullable => 1 },
review_text => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("book");
__PACKAGE__->belongs_to( book => 'MySchema::Book' );
1;
A suitable form for this would be:
elements:
- type: Text
name: title
- type: Block
nested_name: review
elements:
- type: Textarea
name: review_text
For might_have and has_one relationships, you generally shouldn't need
to have a field for the related table's primary key, as DBIx::Class
will handle retrieving the correct row automatically.
You can also set a has_one or might_have relationship using a multi
value field like Select.
elements:
- type: Text
name: title
- type: Select
nested: review
model_config:
resultset: Review
This will load all reviews into the select field. If you select a
review from that list, a current relationship to a review is removed
and the new one is added. This requires that the primary key of the
Review table and the foreign key do not match.
has_many and many_to_many relationships
The general principle is the same as for might_have and has_one above,
except you should use a Repeatable element instead of a Block, and it
needs to contain a Hidden field corresponding to the primary key of the
related table.
The Repeatable block's nested_name must be set to the name of the
relationship.
The Repeable block's increment_field_names must be true (which is the
default value).
The Repeable block's counter_name must be set to the name of a Hidden
field, which is placed outside of the Repeatable block. This field is
used to store a count of the number of repetitions of the Repeatable
block were created. When the form is submitted, this value is used
during $form->process to ensure the form is rebuilt with the correct
number of repetitions.
To allow the user to add new related rows, either empty_rows or
new_rows_max must be set - see "Config options for Repeatable blocks"
below.
For the following DBIx::Class schemas:
package MySchema::Book;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("book");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER" },
title => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->has_many( review => 'MySchema::Review', 'book' );
1;
package MySchema::Review;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("review");
__PACKAGE__->add_columns(
book => { data_type => "INTEGER" },
review_text => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("book");
__PACKAGE__->belongs_to( book => 'MySchema::Book' );
1;
A suitable form for this might be:
elements:
- type: Text
name: title
- type: Hidden
name: review_count
- type: Repeatable
nested_name: review
counter_name: review_count
model_config:
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.
many_to_many selection
To select / deselect rows from a many_to_many relationship, you must
use a multi-valued element, such as a Checkboxgroup or a Select with
multiple set.
The field's name must be set to the name of the many_to_many
relationship.
default_column
If you want to search / associate the related table by a column other
it's primary key, set $field->model_config->{default_column}.
---
element:
- type: Checkboxgroup
name: authors
model_config:
default_column: foo
link_values
If you want to set columns on the link table you can do so if you add a
link_values attribute to model_config:
---
element:
- type: Checkboxgroup
name: authors
model_config:
link_values:
foo: bar
additive
The default implementation will first remove all related objects and
set the new ones (see
http://search.cpan.org/perldoc?DBIx::Class::Relationship::Base#set_$rel).
If you want to add the selected objects to the current set of objects
set additive in the model_config.
---
element:
- type: Checkboxgroup
name: authors
model_config:
additive: 1
options_from_model: 0
"options_from_model" is set to 0 because it will try to fetch all
objects from the result class Authors if model_config is specified
without a resultset attribute.)
COMMON ARGUMENTS
The following items are supported in the optional config hash-ref
argument to the methods default_values, update and create.
base
If you want the method to process a particular Block element, rather
than the whole form, you can pass the element as a base argument.
$form->default_values(
$row,
{
base => $formfu_element,
},
);
nested_base
If you want the method to process a particular Block element by name,
you can pass the name as an argument.
$form->default_values(
$row,
{
nested_base => 'foo',
}'
);
CONFIGURATION
Config options for fields
The following items are supported as model_config options on form
fields.
accessor
If set, accessor will be used as a method-name accessor on the
DBIx::Class row object, instead of using the field name.
ignore_if_empty
If the submitted value is blank, no attempt will be made to save it
to the database.
null_if_empty
If the submitted value is blank, save it as NULL to the database.
Normally an empty string is saved as NULL when its corresponding
field is numeric, and as an empty string when its corresponding field
is a text field. This option is useful for changing the default
behavior for text fields.
delete_if_empty
Useful for editing a "might_have" related row containing only one
field.
If the submitted value is blank, the related row is deleted.
For the following DBIx::Class schemas:
package MySchema::Book;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("book");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER" },
title => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("id");
__PACKAGE__->might_have( review => 'MySchema::Review', 'book' );
1;
package MySchema::Review;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("review");
__PACKAGE__->add_columns(
book => { data_type => "INTEGER" },
review_text => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("book");
__PACKAGE__->belongs_to( book => 'MySchema::Book' );
1;
A suitable form for this would be:
elements:
- type: Text
name: title
- type: Block
nested_name: review
elements:
- type: Text
name: review_text
model_config:
delete_if_empty: 1
label
To use a column value for a form field's label.
Config options for fields within a Repeatable block
delete_if_true
Intended for use on a Checkbox field.
If the checkbox is checked, the following occurs: for a has-many
relationship, the related row is deleted; for a many-to-many
relationship, the relationship link is removed.
An example of use might be:
elements:
- type: Text
name: title
- type: Hidden
name: review_count
- type: Repeatable
nested_name: review
counter_name: review_count
elements:
- type: Hidden
name: book
- type: Textarea
name: review_text
- type: Checkbox
name: delete_review
label: 'Delete Review?'
model_config:
delete_if_true: 1
Note: make sure the name of this field does not clash with one of
your DBIx::Class::Row method names (e.g. "delete") - see "CAVEATS".
Config options for Repeatable blocks
empty_rows
For a Repeatable block corresponding to a has-many or many-to-many
relationship, to allow the user to insert new rows, set empty_rows to
the number of extra repetitions you wish added to the end of the
Repeatable block.
new_rows_max
Set to the maximum number of new rows that a Repeatable block is
allowed to add.
If not set, it will fallback to the value of empty_rows.
Config options for options_from_model
The column used for the element values is set with the model_config
value id_column - or if not set, the table's primary column is used.
element:
- type: Select
name: foo
model_config:
resultset: TableClass
id_column: pk_col
The column used for the element labels is set with the model_config
value label_column - or if not set, the first text/varchar column found
in the table is used - or if one is not found, the id_column is used
instead.
element:
- type: Select
name: foo
model_config:
resultset: TableClass
label_column: label_col
To pass the database label values via the form's localization object,
set localize_label
element:
- type: Select
name: foo
model_config:
localize_label: 1
You can set a condition, which will be passed as the 1st argument to
"search" in DBIx::Class::ResultSet.
element:
- type: Select
name: foo
model_config:
resultset: TableClass
condition:
type: is_foo
You can set a condition_from_stash, which will be passed as the 1st
argument to "search" in DBIx::Class::ResultSet.
key is the column-name to be passed to search, and stash_key is the
name of a key on the form stash from which the value to be passed to
search is found.
element:
- type: Select
name: foo
model_config:
resultset: TableClass
condition_from_stash:
key: stash_key
Is comparable to:
$form->element({
type => 'Select',
name => 'foo',
model_config => {
resultset => 'TableClass',
condition => {
key => $form->stash->{stash_key}
}
}
})
If the value in the stash is nested in a data-structure, you can access
it by setting expand_stash_dots. As you can see in the example below,
it automatically handles calling methods on objects, accessing
hash-keys on hash-references, and accessing array-slots on array
references.
element:
- type: Select
name: foo
model_config:
resultset: TableClass
condition_from_stash:
key: foo.bar.0
expand_stash_dots: 1
Is comparable to:
$form->element({
type => 'Select',
name => 'foo',
model_config => {
resultset => 'TableClass',
condition => {
key => $form->stash->{foo}->bar->[0];
}
}
})
# Where stash returns a hashref.
# The 'foo' hash-key returns an object.
# The object-method 'bar' returns an arrayref.
# The first array slot returns the value used in the query.
You can set attributes, which will be passed as the 2nd argument to
"search" in DBIx::Class::ResultSet.
ENUM Column Type
If the field name matches (case-insensitive) a column name with type
'ENUM' and the Schema contains enum values in
$resultset->column_info($name)->{extra}{list}, the field's options will
be populated with the enum values.
FAQ
Add extra values not in the form
To update values to the database which weren't submitted to the form,
you can first add them to the form with add_valid.
my $passwd = generate_passwd();
$form->add_valid( passwd => $passwd );
$form->model->update( $row );
add_valid works for fieldnames that don't exist in the form.
Set a field read only
You can make a field read only. The value of such fields cannot be
changed by the user even if they submit a value for it.
$field->model_config->{read_only} = 1;
- Name: field
model_config:
read_only: 1
See HTML::FormFu::Element::Label.
CAVEATS
To ensure your column's inflators and deflators are called, we have to
get / set values using their named methods, and not with get_column /
set_column.
Because of this, beware of having column names which clash with
DBIx::Class built-in method-names, such as delete. - It will have
obviously undesirable results!
REMOVED METHODS
new_empty_row
See empty_rows in "Config options for Repeatable blocks" instead.
new_empty_row_multi
See new_rows_max in "Config options for Repeatable blocks" instead.
Range constraint
See empty_rows in "Config options for Repeatable blocks" instead.
SUPPORT
Project Page:
http://code.google.com/p/html-formfu/
Mailing list:
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
Mailing list archives:
http://lists.scsys.co.uk/pipermail/html-formfu/
BUGS
Please submit bugs / feature requests to
http://code.google.com/p/html-formfu/issues/list (preferred) or
http://rt.perl.org.
GITHUB REPOSITORY
This module's sourcecode is maintained in a git repository at
git://github.com/fireartist/HTML-FormFu-Model-DBIC.git
The project page is
https://github.com/fireartist/HTML-FormFu-Model-DBIC
SEE ALSO
HTML::FormFu, DBIx::Class, Catalyst::Controller::HTML::FormFu
AUTHOR
Carl Franks
CONTRIBUTORS
Based on the code of DBIx::Class::HTML::FormFu, which was contributed
to by:
Adam Herzog
Daisuke Maki
Mario Minati
COPYRIGHT AND LICENSE
Copyright (C) 2007 by Carl Franks
Based on the original source code of DBIx::Class::HTMLWidget, copyright
Thomas Klausner.
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either Perl version 5.8.8 or, at
your option, any later version of Perl 5 you may have available.
HTML-FormFu-Model-DBIC-2.03/Makefile.PL 0000644 0001751 0001752 00000003463 13262760616 015553 0 ustar carl carl # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.011.
use strict;
use warnings;
use 5.008001;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "Integrate HTML::FormFu with DBIx::Class",
"AUTHOR" => "Carl Franks ",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "HTML-FormFu-Model-DBIC",
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.008001",
"NAME" => "HTML::FormFu::Model::DBIC",
"PREREQ_PM" => {
"DBD::SQLite" => 0,
"DBIx::Class" => "0.08108",
"HTML::FormFu" => "2.00",
"List::MoreUtils" => 0,
"MooseX::Attribute::Chained" => "1.0.2",
"Storable" => 0,
"Task::Weaken" => 0
},
"TEST_REQUIRES" => {
"DateTime::Format::SQLite" => 0,
"ExtUtils::MakeMaker" => 0,
"File::Spec" => 0,
"Locale::Maketext" => 0,
"SQL::Translator" => "0.11016",
"Test::More" => "0.99"
},
"VERSION" => "2.03",
"test" => {
"TESTS" => "t/*.t t/constraints/*.t t/create/*.t t/default_values/*.t t/options_from_model/*.t t/update/*.t t/x_roundtrip/*.t"
}
);
my %FallbackPrereqs = (
"DBD::SQLite" => 0,
"DBIx::Class" => "0.08108",
"DateTime::Format::SQLite" => 0,
"ExtUtils::MakeMaker" => 0,
"File::Spec" => 0,
"HTML::FormFu" => "2.00",
"List::MoreUtils" => 0,
"Locale::Maketext" => 0,
"MooseX::Attribute::Chained" => "1.0.2",
"SQL::Translator" => "0.11016",
"Storable" => 0,
"Task::Weaken" => 0,
"Test::More" => "0.99"
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
delete $WriteMakefileArgs{TEST_REQUIRES};
delete $WriteMakefileArgs{BUILD_REQUIRES};
$WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs;
}
delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
WriteMakefile(%WriteMakefileArgs);
HTML-FormFu-Model-DBIC-2.03/META.json 0000644 0001751 0001752 00000042270 13262760616 015221 0 ustar carl carl {
"abstract" : "Integrate HTML::FormFu with DBIx::Class",
"author" : [
"Carl Franks "
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.011, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : 2
},
"name" : "HTML-FormFu-Model-DBIC",
"no_index" : {
"directory" : [
"eg",
"examples",
"inc",
"share",
"t",
"xt"
]
},
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"develop" : {
"requires" : {
"File::Spec" : "0",
"IO::Handle" : "0",
"IPC::Open3" : "0",
"Test::CPAN::Meta" : "0",
"Test::EOL" : "0",
"Test::Kwalitee" : "1.21",
"Test::More" : "0.88",
"Test::PAUSE::Permissions" : "0",
"Test::Perl::Critic" : "0",
"Test::Pod" : "1.41"
}
},
"runtime" : {
"requires" : {
"DBD::SQLite" : "0",
"DBIx::Class" : "0.08108",
"HTML::FormFu" : "2.00",
"List::MoreUtils" : "0",
"MooseX::Attribute::Chained" : "v1.0.2",
"Storable" : "0",
"Task::Weaken" : "0",
"perl" : "5.008001"
}
},
"test" : {
"recommends" : {
"CPAN::Meta" : "2.120900"
},
"requires" : {
"DateTime::Format::SQLite" : "0",
"ExtUtils::MakeMaker" : "0",
"File::Spec" : "0",
"Locale::Maketext" : "0",
"SQL::Translator" : "0.11016",
"Test::More" : "0.99"
}
}
},
"provides" : {
"HTML::FormFu::Constraint::DBIC::Unique" : {
"file" : "lib/HTML/FormFu/Constraint/DBIC/Unique.pm",
"version" : "2.03"
},
"HTML::FormFu::Model::DBIC" : {
"file" : "lib/HTML/FormFu/Model/DBIC.pm",
"version" : "2.03"
}
},
"release_status" : "stable",
"resources" : {
"homepage" : "https://github.com/FormFu/HTML-FormFu-Model-DBIC",
"repository" : {
"type" : "git",
"url" : "https://github.com/FormFu/HTML-FormFu-Model-DBIC.git",
"web" : "https://github.com/FormFu/HTML-FormFu-Model-DBIC"
}
},
"version" : "2.03",
"x_Dist_Zilla" : {
"perl" : {
"version" : "5.014004"
},
"plugins" : [
{
"class" : "Dist::Zilla::Plugin::Prereqs",
"config" : {
"Dist::Zilla::Plugin::Prereqs" : {
"phase" : "runtime",
"type" : "requires"
}
},
"name" : "Prereqs",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::Prereqs",
"config" : {
"Dist::Zilla::Plugin::Prereqs" : {
"phase" : "test",
"type" : "requires"
}
},
"name" : "TestRequires",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::Prereqs",
"config" : {
"Dist::Zilla::Plugin::Prereqs" : {
"phase" : "develop",
"type" : "requires"
}
},
"name" : "DevelopRequires",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::Test::Perl::Critic",
"name" : "Test::Perl::Critic",
"version" : "3.001"
},
{
"class" : "Dist::Zilla::Plugin::MetaTests",
"name" : "MetaTests",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::OurPkgVersion",
"name" : "OurPkgVersion",
"version" : "0.12"
},
{
"class" : "Dist::Zilla::Plugin::PodVersion",
"name" : "PodVersion",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::Test::Kwalitee",
"config" : {
"Dist::Zilla::Plugin::Test::Kwalitee" : {
"filename" : "xt/release/kwalitee.t",
"skiptest" : []
}
},
"name" : "Test::Kwalitee",
"version" : "2.12"
},
{
"class" : "Dist::Zilla::Plugin::Test::EOL",
"config" : {
"Dist::Zilla::Plugin::Test::EOL" : {
"filename" : "xt/author/eol.t",
"finder" : [
":InstallModules"
],
"trailing_whitespace" : 1
}
},
"name" : "Test::EOL",
"version" : "0.19"
},
{
"class" : "Dist::Zilla::Plugin::Test::PAUSE::Permissions",
"name" : "Test::PAUSE::Permissions",
"version" : "0.003"
},
{
"class" : "Dist::Zilla::Plugin::GithubMeta",
"name" : "GithubMeta",
"version" : "0.54"
},
{
"class" : "Dist::Zilla::Plugin::NextRelease",
"name" : "NextRelease",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::Git::GatherDir",
"config" : {
"Dist::Zilla::Plugin::GatherDir" : {
"exclude_filename" : [],
"exclude_match" : [],
"follow_symlinks" : 0,
"include_dotfiles" : 0,
"prefix" : "",
"prune_directory" : [],
"root" : "."
},
"Dist::Zilla::Plugin::Git::GatherDir" : {
"include_untracked" : 0
}
},
"name" : "Git::GatherDir",
"version" : "2.043"
},
{
"class" : "Dist::Zilla::Plugin::Git::NextVersion",
"config" : {
"Dist::Zilla::Plugin::Git::NextVersion" : {
"first_version" : "0.001",
"version_by_branch" : 0,
"version_regexp" : "(?^:^v(.+)$)"
},
"Dist::Zilla::Role::Git::Repo" : {
"git_version" : "1.9.1",
"repo_root" : "."
}
},
"name" : "Git::NextVersion",
"version" : "2.043"
},
{
"class" : "Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch",
"config" : {
"Dist::Zilla::Role::Git::Repo" : {
"git_version" : "1.9.1",
"repo_root" : "."
}
},
"name" : "Git::CheckFor::CorrectBranch",
"version" : "0.014"
},
{
"class" : "Dist::Zilla::Plugin::Git::Remote::Check",
"name" : "Git::Remote::Check",
"version" : "0.1.2"
},
{
"class" : "Dist::Zilla::Plugin::PruneCruft",
"name" : "@Starter/PruneCruft",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::ManifestSkip",
"name" : "@Starter/ManifestSkip",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::MetaConfig",
"name" : "@Starter/MetaConfig",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::MetaProvides::Package",
"config" : {
"Dist::Zilla::Plugin::MetaProvides::Package" : {
"finder_objects" : [
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : "@Starter/MetaProvides::Package/AUTOVIV/:InstallModulesPM",
"version" : "6.011"
}
],
"include_underscores" : 0
},
"Dist::Zilla::Role::MetaProvider::Provider" : {
"$Dist::Zilla::Role::MetaProvider::Provider::VERSION" : "2.002004",
"inherit_missing" : 1,
"inherit_version" : 1,
"meta_noindex" : 1
},
"Dist::Zilla::Role::ModuleMetadata" : {
"Module::Metadata" : "1.000033",
"version" : "0.005"
}
},
"name" : "@Starter/MetaProvides::Package",
"version" : "2.004003"
},
{
"class" : "Dist::Zilla::Plugin::MetaNoIndex",
"name" : "@Starter/MetaNoIndex",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::MetaYAML",
"name" : "@Starter/MetaYAML",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::MetaJSON",
"name" : "@Starter/MetaJSON",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::License",
"name" : "@Starter/License",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod",
"config" : {
"Dist::Zilla::Role::FileWatcher" : {
"version" : "0.006"
}
},
"name" : "@Starter/ReadmeAnyFromPod",
"version" : "0.163250"
},
{
"class" : "Dist::Zilla::Plugin::ExecDir",
"name" : "@Starter/ExecDir",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::ShareDir",
"name" : "@Starter/ShareDir",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::PodSyntaxTests",
"name" : "@Starter/PodSyntaxTests",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::Test::ReportPrereqs",
"name" : "@Starter/Test::ReportPrereqs",
"version" : "0.027"
},
{
"class" : "Dist::Zilla::Plugin::Test::Compile",
"config" : {
"Dist::Zilla::Plugin::Test::Compile" : {
"bail_out_on_fail" : 0,
"fail_on_warning" : "author",
"fake_home" : 0,
"filename" : "xt/author/00-compile.t",
"module_finder" : [
":InstallModules"
],
"needs_display" : 0,
"phase" : "develop",
"script_finder" : [
":PerlExecFiles"
],
"skips" : [],
"switch" : []
}
},
"name" : "@Starter/Test::Compile",
"version" : "2.058"
},
{
"class" : "Dist::Zilla::Plugin::MakeMaker",
"config" : {
"Dist::Zilla::Role::TestRunner" : {
"default_jobs" : 1
}
},
"name" : "@Starter/MakeMaker",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::Manifest",
"name" : "@Starter/Manifest",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::TestRelease",
"name" : "@Starter/TestRelease",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::RunExtraTests",
"config" : {
"Dist::Zilla::Role::TestRunner" : {
"default_jobs" : 1
}
},
"name" : "@Starter/RunExtraTests",
"version" : "0.029"
},
{
"class" : "Dist::Zilla::Plugin::ConfirmRelease",
"name" : "@Starter/ConfirmRelease",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::UploadToCPAN",
"name" : "@Starter/UploadToCPAN",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod",
"config" : {
"Dist::Zilla::Role::FileWatcher" : {
"version" : "0.006"
}
},
"name" : "Pod_Readme",
"version" : "0.163250"
},
{
"class" : "Dist::Zilla::Plugin::Git::Check",
"config" : {
"Dist::Zilla::Plugin::Git::Check" : {
"untracked_files" : "die"
},
"Dist::Zilla::Role::Git::DirtyFiles" : {
"allow_dirty" : [
"Changes",
"README.pod",
"dist.ini"
],
"allow_dirty_match" : [],
"changelog" : "Changes"
},
"Dist::Zilla::Role::Git::Repo" : {
"git_version" : "1.9.1",
"repo_root" : "."
}
},
"name" : "@Git/Check",
"version" : "2.043"
},
{
"class" : "Dist::Zilla::Plugin::Git::Commit",
"config" : {
"Dist::Zilla::Plugin::Git::Commit" : {
"add_files_in" : [],
"commit_msg" : "v%v%t - %d%n%n%c"
},
"Dist::Zilla::Role::Git::DirtyFiles" : {
"allow_dirty" : [
"Changes",
"README.pod",
"dist.ini"
],
"allow_dirty_match" : [],
"changelog" : "Changes"
},
"Dist::Zilla::Role::Git::Repo" : {
"git_version" : "1.9.1",
"repo_root" : "."
},
"Dist::Zilla::Role::Git::StringFormatter" : {
"time_zone" : "local"
}
},
"name" : "@Git/Commit",
"version" : "2.043"
},
{
"class" : "Dist::Zilla::Plugin::Git::Tag",
"config" : {
"Dist::Zilla::Plugin::Git::Tag" : {
"branch" : null,
"changelog" : "Changes",
"signed" : 0,
"tag" : "v2.03",
"tag_format" : "v%v%t",
"tag_message" : "v%v%t - %d"
},
"Dist::Zilla::Role::Git::Repo" : {
"git_version" : "1.9.1",
"repo_root" : "."
},
"Dist::Zilla::Role::Git::StringFormatter" : {
"time_zone" : "local"
}
},
"name" : "@Git/Tag",
"version" : "2.043"
},
{
"class" : "Dist::Zilla::Plugin::Git::Push",
"config" : {
"Dist::Zilla::Plugin::Git::Push" : {
"push_to" : [
"origin"
],
"remotes_must_exist" : 1
},
"Dist::Zilla::Role::Git::Repo" : {
"git_version" : "1.9.1",
"repo_root" : "."
}
},
"name" : "@Git/Push",
"version" : "2.043"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":InstallModules",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":IncModules",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":TestFiles",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":ExtraTestFiles",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":ExecFiles",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":PerlExecFiles",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":ShareFiles",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":MainModule",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":AllFiles",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : ":NoFiles",
"version" : "6.011"
},
{
"class" : "Dist::Zilla::Plugin::FinderCode",
"name" : "@Starter/MetaProvides::Package/AUTOVIV/:InstallModulesPM",
"version" : "6.011"
}
],
"zilla" : {
"class" : "Dist::Zilla::Dist::Builder",
"config" : {
"is_trial" : 0
},
"version" : "6.011"
}
},
"x_serialization_backend" : "Cpanel::JSON::XS version 4.02"
}
HTML-FormFu-Model-DBIC-2.03/lib/ 0000775 0001751 0001752 00000000000 13262760616 014343 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/lib/HTML/ 0000775 0001751 0001752 00000000000 13262760616 015107 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/ 0000775 0001751 0001752 00000000000 13262760616 016305 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Constraint/ 0000775 0001751 0001752 00000000000 13262760616 020431 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Constraint/DBIC/ 0000775 0001751 0001752 00000000000 13262760616 021132 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Constraint/DBIC/Unique.pm 0000644 0001751 0001752 00000016741 13262760616 022745 0 ustar carl carl package HTML::FormFu::Constraint::DBIC::Unique;
use strict;
our $VERSION = '2.03'; # VERSION
use Moose;
use MooseX::Attribute::Chained;
extends 'HTML::FormFu::Constraint';
use Carp qw( carp croak );
use HTML::FormFu::Util qw( DEBUG_CONSTRAINTS debug );
has model => ( is => 'rw', traits => ['Chained'] );
has resultset => ( is => 'rw', traits => ['Chained'] );
has column => ( is => 'rw', traits => ['Chained'] );
has method_name => ( is => 'rw', traits => ['Chained'] );
has self_stash_key => ( is => 'rw', traits => ['Chained'] );
has others => ( is => 'rw', traits => ['Chained'] );
has id_field => ( is => 'rw', traits => ['Chained'] );
sub constrain_value {
my ( $self, $value ) = @_;
return 1 if !defined $value || $value eq '';
for (qw/ resultset /) {
if ( !defined $self->$_ ) {
# warn and die, as errors are swallowed by HTML-FormFu
carp "'$_' is not defined";
croak "'$_' is not defined";
}
}
# get stash
my $stash = $self->form->stash;
my $schema;
if ( defined $stash->{schema} ) {
$schema = $stash->{schema};
}
elsif ( defined $stash->{context} && defined $self->model ) {
$schema = $stash->{context}->model( $self->model );
}
elsif ( defined $stash->{context} ) {
$schema = $stash->{context}->model;
}
if ( !defined $schema ) {
# warn and die, as errors are swallowed by HTML-FormFu
carp 'could not find DBIC schema';
croak 'could not find DBIC schema';
}
my $resultset = $schema->resultset( $self->resultset );
if ( !defined $resultset ) {
# warn and die, as errors are swallowed by HTML-FormFu
carp 'could not find DBIC resultset';
croak 'could not find DBIC resultset';
}
if ( my $method_name = $self->method_name ) {
# warn "using $method_name to look for $value";
# need to be able to tell $method_name about record on the form stash
my $pk_val;
if ( defined( my $self_stash_key = $self->self_stash_key ) ) {
if ( defined( my $self_stash = $stash->{ $self_stash_key } ) ) {
my ($pk) = $resultset->result_source->primary_columns;
$pk_val = $self_stash->$pk;
}
}
return $resultset->$method_name( $value, $pk_val );
}
else {
my $column = $self->column || $self->parent->name;
my %others;
if ( $self->others ) {
my @others = ref $self->others ? @{ $self->others }
: $self->others;
my $params = $self->form->input;
%others =
grep {
defined && length
}
map {
$_ => $self->get_nested_hash_value( $params, $_ )
} @others;
}
my $existing_row = eval {
$resultset->find( { %others, $column => $value } );
};
if ( my $error = $@ ) {
# warn and die, as errors are swallowed by HTML-FormFu
carp $error;
croak $error;
}
# if a row exists, first check whether it matches a known object on the
# form stash
if ( $existing_row && defined( my $self_stash_key = $self->self_stash_key ) ) {
if ( defined( my $self_stash = $stash->{ $self_stash_key } ) ) {
my ($pk) = $resultset->result_source->primary_columns;
if ( $existing_row->$pk eq $self_stash->$pk ) {
return 1;
}
}
}
elsif ( $existing_row && defined (my $id_field = $self->id_field ) ) {
my $value = $self->get_nested_hash_value( $self->form->input, $id_field );
if ( defined $value && length $value ) {
my ($pk) = $resultset->result_source->primary_columns;
return ($existing_row->$pk eq $value);
}
}
return !$existing_row;
}
}
after repeatable_repeat => sub {
my ( $self, $repeatable, $new_block ) = @_;
# rename any 'id_field' fields
if ( my $id_field = $self->id_field ) {
my $block_fields = $new_block->get_fields;
my $field = $repeatable->get_field_with_original_name( $id_field, $block_fields );
if ( defined $field ) {
DEBUG_CONSTRAINTS && debug(
sprintf "Repeatable renaming constraint 'id_field' '%s' to '%s'",
$id_field,
$field->nested_name,
);
$self->id_field( $field->nested_name );
}
}
};
1;
__END__
=head1 NAME
HTML::FormFu::Constraint::DBIC::Unique - unique constraint for HTML::FormFu::Model::DBIC
=head1 VERSION
version 2.03
=head1 SYNOPSIS
$form->stash->{schema} = $dbic_schema; # DBIC schema
$form->element('text')
->name('email')
->constraint('DBIC::Unique')
->resultset('User')
;
$form->stash->{context} = $c; # Catalyst context
$form->element('text')
->name('email')
->constraint('DBIC::Unique')
->model('DBIC::User')
;
$form->element('text')
->name('user')
->constraint('DBIC::Unique')
->model('DBIC')
->resultset('User')
;
or in a config file:
---
elements:
- type: text
name: email
constraints:
- Required
- type: DBIC::Unique
model: DBIC::User
- type: text
name: user
constraints:
- Required
- type: DBIC::Unique
model: DBIC::User
column: username
=head1 DESCRIPTION
Checks if the input value exists in a DBIC ResultSet.
=head1 METHODS
=head2 model
Arguments: $string # a Catalyst model name like 'DBIC::User'
=head2 resultset
Arguments: $string # a DBIC resultset name like 'User'
=head2 self_stash_key
reference to a key in the form stash. if this key exists, the constraint
will check if the id matches the one of this element, so that you can
use your own name.
=head2 id_field
Use this key to define reference field which consist of primary key of
resultset. If the field exists (and $self_stash_key not defined), the
constraint will check if the id matches the primary key of row object:
---
elements:
- type: Hidden
name: id
constraints:
- Required
- type: Text
name: value
label: Value
constraints:
- Required
- type: DBIC::Unique
resultset: ControlledVocab
id_field: id
=head2 others
Use this key to manage unique compound database keys which consist of
more than one column. For example, if a database key consists of
'category' and 'value', use a config file such as this:
---
elements:
- type: Text
name: category
label: Category
constraints:
- Required
- type: Text
name: value
label: Value
constraints:
- Required
- type: DBIC::Unique
resultset: ControlledVocab
others: category
=head2 method_name
Name of a method which will be called on the resultset. The method is passed
two argument; the value of the field, and the primary key value (usually `id`)
of the record in the form stash (as defined by self_stash_key). An example
config might be:
---
elements:
- type: text
name: user
constraints:
- Required
- type: DBIC::Unique
model: DBIC::User
method_name: is_username_available
=head2 SEE ALSO
Is a sub-class of, and inherits methods from L
L
=head1 AUTHOR
Jonas Alves C
=head1 LICENSE
This library is free software, you can redistribute it and/or modify it under
the same terms as Perl itself.
HTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Model/ 0000775 0001751 0001752 00000000000 13262760616 017345 5 ustar carl carl HTML-FormFu-Model-DBIC-2.03/lib/HTML/FormFu/Model/DBIC.pm 0000644 0001751 0001752 00000153732 13262760616 020415 0 ustar carl carl package HTML::FormFu::Model::DBIC;
use strict;
use warnings;
use base 'HTML::FormFu::Model';
our $VERSION = '2.03'; # VERSION
use HTML::FormFu::Util qw( _merge_hashes );
use List::MoreUtils qw( none notall );
use List::Util qw( first );
use Scalar::Util qw( blessed reftype );
use Storable qw( dclone );
use Carp qw( croak );
sub options_from_model {
my ( $self, $base, $attrs ) = @_;
my $form = $base->form;
my $resultset = _get_resultset( $base, $form, $attrs );
my $source = $resultset->result_source;
my $id_col = $attrs->{id_column};
my $label_col = $attrs->{label_column};
my $condition = $attrs->{condition};
my $attributes = $attrs->{attributes} || {};
my $enum_col =
first {
lc( $base->name ) eq lc($_);
}
grep {
my $data_type = $source->column_info($_)->{data_type};
defined $data_type && $data_type =~ /enum/i
} $source->columns;
if ( defined $enum_col ) {
return map {
[ $_, $_ ]
} @{ $source->column_info($enum_col)->{extra}{list} };
}
if ( !defined $id_col ) {
($id_col) = $source->primary_columns;
}
if ( !defined $label_col ) {
# use first text column
($label_col) = grep {
my $data_type = $source->column_info($_)->{data_type};
defined $data_type && $data_type =~ /text|varchar/i
} $source->columns;
}
$label_col = $id_col if !defined $label_col;
if ( defined( my $from_stash = $attrs->{condition_from_stash} ) ) {
$condition
= $condition
? { %{$condition} }
: {}; # avoid overwriting attrs->{condition}
for my $name ( keys %$from_stash ) {
croak "config value must not be a reference" if ref $from_stash->{$name};
if ( $attrs->{expand_stash_dots} ) {
$condition->{$name} = $self->_get_stash_value( $form->stash, $from_stash->{$name} );
}
else {
$condition->{$name} = $form->stash->{ $from_stash->{$name} };
}
}
}
# save the expanded condition for later use
$attrs->{'-condition'} = $condition if ($condition);
$attributes->{'-columns'} = [ $id_col, $label_col ];
my $result = $resultset->search( $condition, $attributes );
my @defaults = $result->all;
my $has_column = $source->has_column($label_col);
if ( $attrs->{localize_label} ) {
@defaults = map {
{ value => $_->get_column($id_col),
label_loc => $has_column ? $_->get_column($label_col) : $_->$label_col,
}
} @defaults;
}
else {
@defaults = map { [
$_->get_column($id_col),
$has_column ? $_->get_column($label_col) : $_->$label_col,
]
} @defaults;
}
return @defaults;
}
sub _get_stash_value {
my ( $self, $stash, $key ) = @_;
my $base = $stash;
if ( $key =~ /\./ ) {
for my $part ( grep {length} split qr/\./, $key ) {
if ( blessed($base) && $base->can($part) ) {
$base = $base->$part;
}
elsif ( 'HASH' eq reftype($base) ) {
$base = $base->{$part};
}
elsif ( 'ARRAY' eq reftype($base) && $key =~ /^[0-9]+\z/ ) {
$base = $base->[$key];
}
else {
croak "don't know what to do with part '$part' in key '$key'";
}
}
}
return $base;
}
sub _get_resultset {
my ( $base, $form, $attrs ) = @_;
my $schema = $form->stash->{schema};
my $context = $form->stash->{context};
if ( defined $schema ) {
my $rs_name = $attrs->{resultset} || ucfirst $base->name;
return $schema->resultset($rs_name);
}
elsif ( defined $context && defined $attrs->{model} ) {
my $model = $context->model( $attrs->{model} );
if ( defined( my $rs = $attrs->{resultset} ) ) {
$model = $model->resultset($rs);
}
return $model;
}
elsif ( defined $context ) {
my $model = $context->model;
return $model if defined $model;
}
croak "need a schema or context";
}
sub default_values {
my ( $self, $dbic, $attrs ) = @_;
my $form = $self->form;
my $base = defined $attrs->{base} ? delete $attrs->{base} : $form;
$base = $form->get_all_element( { nested_name => $attrs->{nested_base} } )
if defined $attrs->{nested_base}
&& ( !defined $base->nested_name
|| $base->nested_name ne $attrs->{nested_base} );
_fill_in_fields( $base, $dbic );
_fill_nested( $self, $base, $dbic );
return $form;
}
# returns 0 if there is a node with nested_name set on the path from $field to $base
sub is_direct_child {
my ( $base, $field ) = @_;
while ( defined $field->parent ) {
$field = $field->parent;
return 1 if $base == $field;
return 0 if defined $field->nested_name;
}
}
# fills in values for all direct children fields of $base
sub _fill_in_fields {
my ( $base, $dbic ) = @_;
for my $field ( @{ $base->get_fields } ) {
my $name = $field->name;
my $config = $field->model_config;
next if not defined $name || $config->{accessor};
next if not is_direct_child( $base, $field );
$name = $field->original_name if $field->original_name;
my $accessor = $config->{accessor};
if ( defined $accessor ) {
$field->default( $dbic->$accessor );
}
elsif ( $dbic->can($name) ) {
my $has_col = $dbic->result_source->has_column($name);
my $has_rel = $dbic->result_source->has_relationship($name);
if ( $has_col && $has_rel ) {
# can't use direct accessor, if there's a rel of the same name
$field->default( $dbic->get_column($name) );
}
elsif ($has_col) {
$field->default( $dbic->$name );
}
elsif (
$field->multi_value
&& ($config->{default_column}
|| ( ref( $dbic->$name )
&& $dbic->$name->can('result_source') ) ) )
{
my ($col) = $config->{default_column}
|| $dbic->$name->result_source->primary_columns;
my $info = $dbic->result_source->relationship_info($name);
if ( !defined $info or $info->{attrs}{accessor} eq 'multi' ) {
my @defaults = $dbic->$name->get_column($col)->all;
$field->default( \@defaults );
}
else {
# has_one/might_have
my ($pk) = $dbic->result_source->primary_columns;
$field->default( $dbic->$name->$pk );
}
}
else {
# This field is a method expected to return the value
$field->default( $dbic->$name );
}
}
# handle {label}
if ( defined( my $label = $config->{label} ) ) {
my $has_rel = $dbic->result_source->has_relationship($label);
if ($has_rel) {
# can't use direct accessor, if there's a rel of the same name
$field->label( $dbic->get_column($label) );
}
else {
$field->label( $dbic->$label );
}
}
}
}
# loop over all child blocks with nested_name that is a method on the DBIC row
# and recurse
sub _fill_nested {
my ( $self, $base, $dbic ) = @_;
for my $block ( @{ $base->get_all_elements } ) {
next if $block->is_field && !$block->is_block;
next if !$block->can('nested_name');
my $config = $block->model_config;
# first handle {label}
if ( defined( my $label = $config->{label} ) && $block->can('label') ) {
my $has_rel = $dbic->result_source->has_relationship($label);
if ($has_rel) {
# can't use direct accessor, if there's a rel of the same name
$block->label( $dbic->get_column($label) );
}
else {
$block->label( $dbic->$label );
}
}
my $rel = $block->nested_name;
next if !defined $rel;
my $has_rel = $dbic->result_source->relationship_info($rel)
|| ( $dbic->can($rel) && $dbic->can( 'add_to_' . $rel ) )
; # many_to_many
# recursing only when $rel is a relation or non-column accessor on $dbic
next
unless $has_rel
|| ( $dbic->can($rel)
&& !$dbic->result_source->has_column($rel) );
if ( $block->is_repeatable && $block->increment_field_names ) {
# check there's a field name matching the PK
my ($pk) = $dbic->$rel->result_source->primary_columns;
next
unless grep {
$pk eq
( defined $_->original_name ? $_->original_name : $_->name )
} @{ $block->get_fields( { type => 'Hidden' } ) };
my @rows = $dbic->$rel->all;
my $count
= $config->{empty_rows}
? scalar @rows + $config->{empty_rows}
: scalar @rows;
my $blocks = $block->repeat($count);
$block->process;
for my $rep ( 0 .. $#rows ) {
default_values( $self, $rows[$rep],
{ base => $blocks->[$rep] } );
}
# set the counter field to the number of rows
if ( defined( my $param_name = $block->counter_name ) ) {
my ($field) = grep {
$param_name eq (
defined $_->original_name
? $_->original_name
: $_->name )
} @{ $base->get_fields };
$field->default($count)
if defined $field;
}
# remove 'delete' checkbox from the last repetition ?
if ( $config->{empty_rows} ) {
my $new_row_count
= $config->{empty_rows}
? $config->{empty_rows}
: 1;
my @reps = reverse @{ $block->get_elements };
for my $i ( 0 .. ( $new_row_count - 1 ) ) {
my $rep = $reps[$i];
my ($del_field)
= grep { $_->model_config->{delete_if_true} }
@{ $rep->get_fields };
if ( defined $del_field ) {
$del_field->parent->remove_element($del_field);
}
}
}
}
else {
if ( defined( my $row = $dbic->$rel ) ) {
default_values( $self, $row, { base => $block } );
}
}
}
return;
}
sub create {
my ( $self, $attrs ) = @_;
croak "invalid arguments" if @_ > 2;
my $form = $self->form;
my $base = defined $attrs->{base} ? delete $attrs->{base} : $form;
my $schema = $form->stash->{schema}
or croak 'schema required on form stash, if no row object provided';
my $resultset
= $attrs->{resultset}
|| $base->model_config->{resultset}
|| $form->model_config->{resultset}
or croak 'could not find resultset name';
$resultset = $schema->resultset($resultset);
my $dbic = $resultset->new_result( {} );
return $self->update( $dbic, { %$attrs, base => $base } );
}
sub update {
my ( $self, $dbic, $attrs ) = @_;
croak "row object missing" if !defined $dbic;
my $form = $self->form;
my $base = defined $attrs->{base} ? delete $attrs->{base} : $form;
$base = $form->get_all_element( { nested_name => $attrs->{nested_base} } )
if defined $attrs->{nested_base}
&& ( !defined $base->nested_name
|| $base->nested_name ne $attrs->{nested_base} );
my $rs = $dbic->result_source;
my @rels = $rs->relationships;
my @cols = $rs->columns;
# check for belongs_to relationships with a required foreign key
my (@belongs_to_rels, @other_rels);
foreach my $rel (@rels) {
# 'fk_columns' is set for belong_to rels in DBIx::Class::Relationship::BelongsTo
my @fk_columns = keys %{ $dbic->relationship_info($rel)->{attrs}{fk_columns} };
if (@fk_columns) {
push @belongs_to_rels, $rel;
} else {
push @other_rels, $rel;
}
}
# add belongs_to rels before insert
if (@belongs_to_rels) {
# tell _save_relationships not to update $dbic yet, just add the rels
my %attrs = ( %$attrs, no_update => 1 );
_save_relationships( $self, $base, $dbic, $form, $rs, \%attrs, \@belongs_to_rels );
}
_save_columns( $base, $dbic, $form ) or return;
$dbic->update_or_insert;
_save_relationships( $self, $base, $dbic, $form, $rs, $attrs, \@other_rels );
_save_multi_value_fields_many_to_many( $base, $dbic, $form, $attrs, \@rels,
\@cols );
_save_repeatable_many_to_many( $self, $base, $dbic, $form, $attrs, \@rels,
\@cols );
# handle non-rel, non-column, nested_base accessors.
# - this highlights a failing of the approach of iterating over
# db cols + rels - we should maybe refactor to iterate over
# form blocks and fields instead ?
for my $block ( @{ $base->get_all_elements } ) {
next if $block->is_field;
next if !$block->can('nested_name');
my $rel = $block->nested_name;
next if !defined $rel;
next unless $dbic->can($rel);
next if grep { $rel eq $_ } @cols;
next if grep { $rel eq $_ } @rels;
next if $dbic->can( "add_to_" . $rel ); # many-to-many
if ( defined( my $row = $dbic->$rel ) ) {
update( $self, $row, { base => $block } );
}
}
return $dbic;
}
sub _save_relationships {
my ( $self, $base, $dbic, $form, $rs, $attrs, $rels ) = @_;
return if $attrs->{no_follow};
for my $rel (@$rels) {
# 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, {} );
if ( !defined $target && grep { length $_ } values %$params ) {
$target = $dbic->new_related( $rel, {} );
}
next if !defined $target;
update(
$self, $target,
{ %$attrs,
base => $block,
nested_base => $rel,
from => $dbic->result_class,
} );
unless ( $dbic->$rel ) {
$dbic->$rel($target);
$dbic->update unless $attrs->{no_update};
}
}
elsif ( defined $multi_value ) {
# belongs_to, has_one or might_have relationship
my $info = $dbic->result_source->relationship_info($rel);
my @fpkey = $dbic->related_resultset($rel)
->result_source->primary_columns;
my @cond = ( %{ $info->{cond} } );
# make sure $rel is a has_one or might_have rel
# stolen from SQL/Translator/Parser/DBIx/Class
my $fk_constraint;
# Get the key information, mapping off the foreign/self markers
my @refkeys = map {/^\w+\.(\w+)$/} @cond;
my @keys = map { $info->{cond}{$_} =~ /^\w+\.(\w+)$/ }
grep { exists $info->{cond}{$_} } @cond;
#first it can be specified explicitly
if ( exists $info->{attrs}{is_foreign_key_constraint} ) {
$fk_constraint = $info->{attrs}{is_foreign_key_constraint};
}
# it can not be multi
elsif ($info->{attrs}{accessor}
&& $info->{attrs}{accessor} eq 'multi' )
{
$fk_constraint = 0;
}
# if indeed single, check if all self.columns are our primary keys.
# this is supposed to indicate a has_one/might_have...
# where's the introspection!!?? :)
else {
$fk_constraint
= not _compare_relationship_keys( \@keys, \@fpkey );
}
next if ($fk_constraint);
my $fpkey = shift @fpkey;
my ( $fkey, $skey ) = @cond;
$fkey =~ s/^foreign\.//;
$skey =~ s/^self\.//;
my $fclass = $info->{class};
croak
'The primary key and the foreign key may not be the same column in class '
. $fclass
if $fpkey eq $fkey;
croak
'multiple primary keys are not supported for has_one/might_have relationships'
if ( @fpkey > 1 );
my $schema = $dbic->result_source->schema;
# use transactions if supported by storage
$schema->txn_do(
sub {
# reset any previous items which were related to $dbic
$rs->schema->resultset($fclass)
->search( { $fkey => $dbic->$skey } )
->update( { $fkey => undef } );
# set new related item
my $updated
= $rs->schema->resultset($fclass)
->search( { $fpkey => $params } )
->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;
if ( defined $select_value && length $select_value ) {
my $pk_name = $combo->model_config->{select_column};
$target = $target_rs->find(
{
$pk_name => $select_value,
},
);
}
else {
my $column_name = $combo->model_config->{text_column};
$target = $target_rs->create(
{
$column_name => $text_value,
},
);
}
$dbic->set_from_related( $rel, $target );
$dbic->update;
}
# Copied from DBIx::Class::ResultSource
sub _compare_relationship_keys {
my ( $keys1, $keys2 ) = @_;
# Make sure every keys1 is in keys2
my $found;
foreach my $key (@$keys1) {
$found = 0;
foreach my $prim (@$keys2) {
if ( $prim eq $key ) {
$found = 1;
last;
}
}
last unless $found;
}
# Make sure every key2 is in key1
if ($found) {
foreach my $prim (@$keys2) {
$found = 0;
foreach my $key (@$keys1) {
if ( $prim eq $key ) {
$found = 1;
last;
}
}
last unless $found;
}
}
return $found;
}
sub _save_has_many {
my ( $self, $dbic, $form, $rs, $block, $rel, $attrs ) = @_;
return unless $block->increment_field_names;
# check there's a field name matching the PK
my ($pk) = $rs->related_source($rel)->primary_columns;
return
unless grep { $_->original_name eq $pk }
@{ $block->get_fields( { type => 'Hidden' } ) };
my @blocks = @{ $block->get_elements };
my $max = $#blocks;
my $config = $block->model_config;
my $new_rows_max = $config->{new_rows_max} || $config->{empty_rows} || 0;
my $new_rows_counter = 0;
# iterate over blocks, not rows
# new rows might have been created in the meantime
for my $i ( 0 .. $max ) {
my $rep = $blocks[$i];
# find PK field
my ($pk_field)
= grep { $_->original_name eq $pk }
@{ $rep->get_fields( { type => 'Hidden' } ) };
next if !defined $pk_field;
my $value = $form->param_value( $pk_field->nested_name );
my $row;
if (( !defined $value || $value eq '' )
&& ( $new_rows_max
&& ( ++$new_rows_counter <= $new_rows_max ) ) )
{
# insert a new row
$row = _insert_has_many( $dbic, $form, $config, $rep, $rel,
$pk_field );
next if !defined $row;
}
elsif ( !defined $value || $value eq '' ) {
next;
}
else {
$row = $dbic->find_related( $rel, $value );
}
next if !defined $row;
# should we delete the row?
next if _delete_has_many( $form, $row, $rep );
update(
$self, $row,
{ %$attrs,
base => $rep,
repeat_base => $rel,
from => $dbic->result_class,
} );
}
}
sub _insert_has_many {
my ( $dbic, $form, $config, $repetition, $rel, $pk_field ) = @_;
return
if !_can_insert_new_row( $dbic, $form, $config, $repetition, $rel,
$pk_field );
my $row = $dbic->new_related( $rel, {} );
return $row;
}
sub _can_insert_new_row {
my ( $dbic, $form, $config, $repetition, $rel, $pk_field ) = @_;
my @rep_fields = @{ $repetition->get_fields };
my $pk_name = $pk_field->nested_name;
my @constraints = grep { $_->when->{field} eq $pk_name }
grep { defined $_->when }
map { @{ $_->get_constraints( { type => 'Required' } ) } } @rep_fields;
my @required_fields;
if (@constraints) {
# if there are any Required constraints whose 'when' clause points to
# the PK field - check that all these fields are filled in - as
# the PK value is missing on new reps, so the constraint won't have run
return
if notall { defined && length }
map { $form->param_value( $_->nested_name ) }
map { $_->parent } @constraints;
}
else {
# otherwise, just check at least 1 field that matches either a column
# name or an accessor, is filled in
my $result_source = $dbic->$rel->result_source;
# only create a new record if (read from bottom)...
return
if none { defined && length }
map { $form->param_value( $_->nested_name ) }
grep {
$result_source->has_column( $_->original_name )
|| $result_source->can( $_->original_name )
}
grep { defined $_->original_name } @rep_fields;
}
return 1;
}
sub _delete_has_many {
my ( $form, $row, $rep ) = @_;
my ($del_field)
= grep { $_->model_config->{delete_if_true} } @{ $rep->get_fields };
return if !defined $del_field;
my $nested_name = $del_field->nested_name;
return
unless $form->valid($nested_name)
&& $form->param_value($nested_name);
$row->delete if ( $row->in_storage );
return 1;
}
sub _fix_value {
my ( $dbic, $col, $value, $field, ) = @_;
my $col_info = $dbic->column_info($col);
my $is_nullable = $col_info->{is_nullable} || 0;
my $data_type = $col_info->{data_type} || '';
if ( defined $value ) {
if ( ( ( $is_nullable
&& $data_type =~ m/^timestamp|date|int|float|numeric/i
) or $field->model_config->{null_if_empty} )
# comparing to '' does not work for inflated objects
&& !ref $value
&& $value eq ''
)
{
$value = undef;
}
}
if ( !defined $value
&& defined $field
&& $field->isa('HTML::FormFu::Element::Checkbox')
&& !$is_nullable )
{
$value = 0;
}
return $value;
}
sub _save_columns {
my ( $base, $dbic, $form ) = @_;
for my $field ( @{ $base->get_fields }, ) {
next if not is_direct_child( $base, $field );
my $config = $field->model_config;
next if $config->{delete_if_true};
next if $config->{read_only};
my $name = $field->name;
$name = $field->original_name if $field->original_name;
my $accessor = $config->{accessor} || $name;
next if not defined $accessor;
my $value = ( $dbic->result_source->has_column($accessor)
and exists $dbic->result_source->column_info($accessor)->{is_array} )
? $form->param_array( $field->nested_name )
: $form->param_value( $field->nested_name ) ;
next
if $config->{ignore_if_empty}
&& ( !defined $value || $value eq "" );
my ($pk) = $dbic->result_source->primary_columns;
# don't set primary key to null or '' - for Pg SERIALs
next if ( $name eq $pk ) && !( defined $value && length $value );
if ( $config->{delete_if_empty}
&& ( !defined $value || !length $value ) )
{
$dbic->discard_changes if $dbic->is_changed;
$dbic->delete if $dbic->in_storage;
return;
}
if ( $dbic->result_source->has_column($accessor) ) {
$value = _fix_value( $dbic, $accessor, $value, $field );
}
elsif ( $field->isa('HTML::FormFu::Element::Checkbox') ) {
# We are a checkbox.
unless ( defined $value ) {
$value = 0;
}
}
if ( !$config->{accessor}
and $dbic->result_source->has_relationship($accessor)
and $dbic->result_source->has_column($accessor) )
{
$dbic->set_column( $accessor, $value );
}
elsif (
$dbic->can($accessor)
# and $accessor is not a has_one or might_have rel where the foreign key is on the foreign table
and !$dbic->result_source->relationship_info($accessor)
and !$dbic->can( 'add_to_' . $accessor ) )
{
$dbic->$accessor($value);
}
else {
# We should just ignore
#croak "cannot call $accessor on $dbic";
}
}
# for values inserted by add_valid - and not correlated to any field in the form
my $parent = $base;
do {
return 1 if defined $parent->nested_name;
$parent = $parent->parent;
} until ( !defined $parent );
for my $valid ( $form->valid ) {
next if @{ $base->get_fields( name => $valid ) };
next if not $dbic->can($valid);
my $value = $form->param_value($valid);
$dbic->$valid($value);
}
return 1;
}
sub _save_multi_value_fields_many_to_many {
my ( $base, $dbic, $form, $attrs, $rels, $cols ) = @_;
my @fields = grep {
( defined $attrs->{nested_base} && defined $_->parent->nested_name )
? $_->parent->nested_name eq $attrs->{nested_base}
: !$_->nested
}
grep { $_->multi_value }
grep { defined $_->name } @{ $base->get_fields };
for my $field (@fields) {
my $name = $field->name;
next if grep { $name eq $_ } @$rels, @$cols;
if ( $dbic->can($name) ) {
my $related = $dbic->$name;
next if !blessed($related) || !$related->can('result_source');
my $nested_name = $field->nested_name;
next if $form->has_errors($nested_name);
my @values = $form->param_list($nested_name);
my @rows;
my $config = $field->model_config;
next if $config->{read_only};
my ($pk) = $config->{default_column}
|| $related->result_source->primary_columns;
if (@values) {
$pk = "me.$pk" unless $pk =~ /\./;
@rows = $related->result_source->resultset->search( {
%{ $config->{condition} || {} },
$pk => { -in => \@values } } )->all;
}
if ( $config->{additive} ) {
$pk =~ s/^.*\.//;
my $set_method = "add_to_$name";
my $remove_method = "remove_from_$name";
foreach my $row (@rows) {
$dbic->$remove_method($row);
$dbic->$set_method( $row, $config->{link_values} );
}
}
else {
# check if there is a restricting condition on here
# if so life is more complex
my $condition = $config->{'-condition'};
if ($condition) {
my $set_method = "add_to_$name";
my $remove_method = "remove_from_$name";
foreach ( $dbic->$name->search($condition)->all ) {
$dbic->$remove_method($_);
}
foreach my $row (@rows) {
$dbic->$set_method( $row, $config->{link_values} );
}
}
else {
my $set_method = "set_$name";
$dbic->$set_method( \@rows, $config->{link_values} );
}
}
}
}
}
sub _save_repeatable_many_to_many {
my ( $self, $base, $dbic, $form, $attrs, $rels, $cols ) = @_;
my @blocks
= grep { !$_->is_field && $_->is_repeatable && $_->increment_field_names }
@{ $base->get_all_elements };
for my $block (@blocks) {
my $rel = $block->nested_name;
next if !defined $rel;
next if grep { $rel eq $_ } @$rels, @$cols;
if ( $dbic->can($rel) ) {
# check there's a field name matching the PK
my ($pk) = $dbic->$rel->result_source->primary_columns;
my @blocks = @{ $block->get_elements };
my $max = $#blocks;
# iterate over blocks, not rows
# new rows might have been created in the meantime
for my $i ( 0 .. $max ) {
my $rep = $blocks[$i];
# find PK field
my ($pk_field)
= grep { $_->original_name eq $pk }
@{ $rep->get_fields( { type => 'Hidden' } ) };
next if !defined $pk_field;
my $value = $form->param_value( $pk_field->nested_name );
my $row;
my $is_new;
my $config = $block->model_config;
my $new_rows_max
= $config->{new_rows_max}
|| $config->{empty_rows}
|| 0;
my $new_rows_counter = 0;
if (( !defined $value || $value eq '' )
&& ( $new_rows_max
&& ( ++$new_rows_counter <= $new_rows_max ) ) )
{
# insert a new row
$row = _insert_many_to_many( $dbic, $form, $config, $rep,
$rel, $pk_field );
next if !defined $row;
$is_new = 1;
}
elsif ( !defined $value || $value eq '' ) {
next;
}
else {
$row = $dbic->$rel->find($value);
}
next if !defined $row;
# should we delete the row?
next if _delete_many_to_many( $form, $dbic, $row, $rel, $rep );
update(
$self, $row,
{ %$attrs,
base => $rep,
repeat_base => $rel,
from => $dbic->result_class,
} );
if ($is_new) {
# new rows need to be related
my $add_method = "add_to_$rel";
$dbic->$add_method($row);
}
}
}
}
return;
}
sub _insert_many_to_many {
my ( $dbic, $form, $config, $repetition, $rel, $pk_field ) = @_;
return
if !_can_insert_new_row( $dbic, $form, $config, $repetition, $rel,
$pk_field );
my $row = $dbic->$rel->new( {} );
# add_to_* will be called later, after update is called on this row
return $row;
}
sub _delete_many_to_many {
my ( $form, $dbic, $row, $rel, $rep ) = @_;
my ($del_field)
= grep { $_->model_config->{delete_if_true} } @{ $rep->get_fields };
return if !defined $del_field;
my $nested_name = $del_field->nested_name;
return
unless $form->valid($nested_name)
&& $form->param_value($nested_name);
my $remove = "remove_from_$rel";
$dbic->$remove($row);
return 1;
}
1;
__END__
=head1 NAME
HTML::FormFu::Model::DBIC - Integrate HTML::FormFu with DBIx::Class
=head1 VERSION
version 2.03
=head1 SYNOPSIS
Example of typical use in a Catalyst controller:
sub edit : Chained {
my ( $self, $c ) = @_;
my $form = $c->stash->{form};
my $book = $c->stash->{book};
if ( $form->submitted_and_valid ) {
# update dbic row with submitted values from form
$form->model->update( $book );
$c->response->redirect( $c->uri_for('view', $book->id) );
return;
}
elsif ( !$form->submitted ) {
# use dbic row to set form's default values
$form->model->default_values( $book );
}
return;
}
=head1 SETUP
For the form object to be able to access your L schema, it needs
to be placed on the form stash, with the name C.
This is easy if you're using L, as you can
set this up to happen in your Catalyst app's config file.
For example, if your model is named C, you would set this
(in L format):
schema Corp
Or if your app's config file is in L format:
'Controller::HTML::FormFu':
model_stash:
schema: Corp
=head1 METHODS
=head2 default_values
Arguments: $dbic_row, [\%config]
Return Value: $form
$form->model->default_values( $dbic_row );
Set a form's default values from the database, to allow a user to edit them.
=head2 update
Arguments: [$dbic_row], [\%config]
Return Value: $dbic_row
$form->model->update( $dbic_row );
Update the database with the submitted form values.
=head2 create
Arguments: [\%config]
Return Value: $dbic_row
my $dbic_row = $form->model->create( {resultset => 'Book'} );
Like L, but doesn't require a C<$dbic_row> argument.
You need to ensure the DBIC schema is available on the form stash - see
L for an example config.
The C must be set either in the method arguments, or the form or
block's C.
An example of setting the ResultSet name on a Form:
---
model_config:
resultset: FooTable
elements:
# [snip]
=head2 options_from_model
Populates a multi-valued field with values from the database.
This method should not be called directly, but is called for you during
C<< $form->process >> by fields that inherit from
L. This includes:
=over
=item L
=item L
=item L
=item L
=back
To use you must set the appropriate C on the element C:
element:
- type: Select
name: foo
model_config:
resultset: TableClass
=head1 BUILDING FORMS
=head2 single table
To edit the values in a row with no related rows, the field names simply have
to correspond to the database column names.
For the following DBIx::Class schema:
package MySchema::Book;
use base 'DBIx::Class';
__PACKAGE__->load_components(qw/ Core /);
__PACKAGE__->table("book");
__PACKAGE__->add_columns(
id => { data_type => "INTEGER" },
title => { data_type => "TEXT" },
author => { data_type => "TEXT" },
blurb => { data_type => "TEXT" },
);
__PACKAGE__->set_primary_key("id");
1;
A suitable form for this might be:
elements:
- type: Text
name: title
- type: Text
name: author
- type: Textarea
name: blurb
=head2 might_have and has_one relationships
Set field values from a related row with a C or C
relationship by placing the fields within a
L (or any element that inherits from
Block, such as L