HTML-FormFu-Model-DBIC-2.00000755001751001752 012331707756 14173 5ustar00carlcarl000000000000README100644001751001752 60012331707756 15110 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00 This archive contains the distribution HTML-FormFu-Model-DBIC, version 2.00: Integrate HTML::FormFu with DBIx::Class This software is copyright (c) 2013 by Carl Franks. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v5.015. Changes100644001751001752 1075612331707756 15600 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.002.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 LICENSE100644001751001752 4365212331707756 15313 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00This software is copyright (c) 2013 by Carl Franks. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2013 by Carl Franks. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2013 by Carl Franks. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End dist.ini100644001751001752 120212331707756 15713 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00name = HTML-FormFu-Model-DBIC author = Carl Franks license = Perl_5 copyright_holder = Carl Franks copyright_year = 2013 version = 2.00 [Prereqs] perl = 5.008001 DBD::SQLite = 0 DBIx::Class = 0.08108 HTML::FormFu = 2.00 List::MoreUtils = 0 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 [PodCoverageTests] [PodSyntaxTests] [PkgVersion] [NextRelease] format = %v %{yyyy-MM-dd}d [Repository] [@Basic] META.yml100644001751001752 137112331707756 15527 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00--- abstract: 'Integrate HTML::FormFu with DBIx::Class' author: - 'Carl Franks ' build_requires: DateTime::Format::SQLite: '0' Locale::Maketext: '0' SQL::Translator: '0.11016' Test::More: '0.99' configure_requires: ExtUtils::MakeMaker: '6.30' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.015, CPAN::Meta::Converter version 2.140640' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: HTML-FormFu-Model-DBIC requires: DBD::SQLite: '0' DBIx::Class: '0.08108' HTML::FormFu: '2.00' List::MoreUtils: '0' Storable: '0' Task::Weaken: '0' perl: '5.008001' resources: repository: git://github.com/fireartist/HTML-FormFu-Model-DBIC.git version: '2.00' MANIFEST100644001751001752 1624212331707756 15432 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.015. Changes LICENSE MANIFEST META.yml Makefile.PL README dist.ini lib/HTML/FormFu/Constraint/DBIC/Unique.pm lib/HTML/FormFu/Model/DBIC.pm 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/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 Makefile.PL100644001751001752 320612331707756 16227 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.015. use strict; use warnings; use 5.008001; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "Integrate HTML::FormFu with DBIx::Class", "AUTHOR" => "Carl Franks ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "HTML-FormFu-Model-DBIC", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "HTML::FormFu::Model::DBIC", "PREREQ_PM" => { "DBD::SQLite" => 0, "DBIx::Class" => "0.08108", "HTML::FormFu" => "2.00", "List::MoreUtils" => 0, "Storable" => 0, "Task::Weaken" => 0 }, "TEST_REQUIRES" => { "DateTime::Format::SQLite" => 0, "Locale::Maketext" => 0, "SQL::Translator" => "0.11016", "Test::More" => "0.99" }, "VERSION" => "2.00", "test" => { "TESTS" => "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, "HTML::FormFu" => "2.00", "List::MoreUtils" => 0, "Locale::Maketext" => 0, "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); create000755001751001752 012331707756 15622 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/tbasic.t100644001751001752 161612331707756 17234 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/createuse 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' ) } lib000755001751001752 012331707756 15125 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/tMySchema.pm100644001751001752 15612331707756 17313 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/libpackage MySchema; use strict; use warnings; use base 'DBIx::Class::Schema'; __PACKAGE__->load_classes; 1; update000755001751001752 012331707756 15641 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/thas_one.t100644001751001752 213012331707756 17576 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } basic.yml100644001751001752 151212331707756 17604 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 methods.t100644001751001752 215112331707756 17630 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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); } basic.yml100644001751001752 122312331707756 17564 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/create--- 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 nested.yml100644001751001752 135712331707756 20014 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 has_one.yml100644001751001752 42212331707756 20116 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 methods.yml100644001751001752 23712331707756 20151 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- elements: - type: Text name: method_test - type: Select name: method_select_test - type: Checkbox name: method_checkbox_test add_valid.t100644001751001752 170412331707756 20077 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } DBICTestLib.pm100644001751001752 103412331707756 17611 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/libpackage 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; belongs_to.t100644001751001752 152612331707756 20325 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } might_have.t100644001751001752 205612331707756 20304 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } MySchema000755001751001752 012331707756 16633 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/libBand.pm100644001751001752 111612331707756 20174 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; User.pm100644001751001752 302512331707756 20247 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; Task.pm100644001751001752 101712331707756 20232 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; Note.pm100644001751001752 70612331707756 20221 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; Type.pm100644001751001752 51412331707756 20232 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; opt_accessor.t100644001751001752 161712331707756 20657 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } basic_create.t100644001751001752 301012331707756 20564 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } might_have.yml100644001751001752 42612331707756 20621 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 basic_update.t100644001751001752 300112331707756 20603 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } Type2.pm100644001751001752 51612331707756 20316 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; default_values000755001751001752 012331707756 17362 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/tlabel.t100644001751001752 140012331707756 20761 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } basic.t100644001751001752 600412331707756 20770 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } nested_create.t100644001751001752 212712331707756 20775 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ) } null_if_empty.t100644001751001752 231712331707756 21037 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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, "" ); } has_one_no_id.t100644001751001752 200012331707756 20742 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } HTMLFormFu000755001751001752 012331707756 17010 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/libI18N.pm100644001751001752 26712331707756 20152 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/HTMLFormFupackage HTMLFormFu::I18N; use strict; use warnings; use base 'Locale::Maketext'; *loc = \&localize; sub localize { my $self = shift; return $self->maketext(@_); } 1; Master.pm100644001751001752 455512331707756 20575 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; MySchemaRS000755001751001752 012331707756 17100 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/libUser.pm100644001751001752 100712331707756 20512 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemaRSpackage 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; opt_accessor.yml100644001751001752 26712331707756 21175 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit has_one_select.t100755001751001752 276412331707756 21155 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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=/); } has_one_create.t100644001751001752 177212331707756 21134 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } TwoNote.pm100644001751001752 74712331707756 20720 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; Address.pm100644001751001752 101512331707756 20713 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; Manager.pm100644001751001752 62212331707756 20663 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; HasMany.pm100644001751001752 71412331707756 20653 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; x_roundtrip000755001751001752 012331707756 16734 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/tcheckbox.yml100644001751001752 12012331707756 21356 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/x_roundtrip--- elements: - name: id - type: Checkbox name: checkbox_col has_one.t100644001751001752 226512331707756 21330 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } basic.yml100644001751001752 132712331707756 21331 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 methods.t100644001751001752 103412331707756 21350 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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" ); } label.yml100644001751001752 25512331707756 21306 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name model_config: label: title - type: Submit name: submit ignore_if_empty.t100644001751001752 146712331707756 21355 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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, " " ); } has_one_no_id.yml100644001751001752 34512331707756 21272 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 null_if_empty.yml100644001751001752 24212331707756 21350 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- model_config: resultset: User elements: - type: Text name: name - type: Text name: title model_config: null_if_empty: 1 Schedule.pm100644001751001752 114412331707756 21065 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; UserBand.pm100644001751001752 111612331707756 21033 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; constraints000755001751001752 012331707756 16726 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/tdbic_unique.t100644001751001752 1025412331707756 21564 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/constraintsuse 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 ], ); } has_one_select.yml100644001751001752 32312331707756 21455 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 I18N000755001751001752 012331707756 17467 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/HTMLFormFuen.pm100644001751001752 24312331707756 20546 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/HTMLFormFu/I18Npackage HTMLFormFu::I18N::en; use strict; use warnings; use base qw( HTMLFormFu::I18N ); our %Lexicon = ( label_foo => 'Foo', label_bar => 'Bar', ); 1; has_one.yml100644001751001752 34512331707756 21643 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 methods.yml100644001751001752 15012331707756 21664 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- elements: - type: Text name: method_test - type: Select name: method_select_testignore_if_empty.yml100644001751001752 17412331707756 21665 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- model_config: resultset: User elements: - type: Password name: name model_config: ignore_if_empty: 1 belongs_to_create.t100644001751001752 127012331707756 21644 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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'); belongs_to_select.t100644001751001752 247612331707756 21671 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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'); } might_have_create.t100644001751001752 215412331707756 21626 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } dbic_unique.yml100644001751001752 37312331707756 22063 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/constraints--- 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 might_have.t100644001751001752 244512331707756 22027 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } ManagedBand.pm100644001751001752 116712331707756 21457 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/MySchemapackage 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; Model000755001751001752 012331707756 17664 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/lib/HTML/FormFuDBIC.pm100644001751001752 15105512331707756 21132 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/lib/HTML/FormFu/Modelpackage HTML::FormFu::Model::DBIC; $HTML::FormFu::Model::DBIC::VERSION = '2.00'; use strict; use warnings; use base 'HTML::FormFu::Model'; use HTML::FormFu::Util qw( _merge_hashes ); use List::MoreUtils qw( none notall ); use List::Util qw( first ); use Scalar::Util qw( blessed ); 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}; my $value = $form->stash->{ $from_stash->{$name} }; $condition->{$name} = $value; } } # 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_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) ) { $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 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) with its L 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 C and C 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 C or C relationship using a multi value field like L. 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 C table and the foreign key do not match. =head2 has_many and many_to_many relationships The general principle is the same as for C and C above, except you should use a L element instead of a Block, and it needs to contain a L field corresponding to the foreign key. The Repeatable block's L must be set to the name of the relationship. The Repeable block's L must be true (which is the default value). The Repeable block's L must be set to the name of a L 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 C<< $form->process >> to ensure the form is rebuilt with the correct number of repetitions. To allow the user to add new related rows, either C or C must be set - see L 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 =head2 belongs_to relationships Belongs-to relationships can be edited / created with a ComboBox element. If the user selects a value with the Select field, the belongs-to will be set to an already-existing row in the related table. If the user enters a value into the Text field, the belongs-to will be set using a newly-created row in the related table. elements: - type: ComboBox name: author model_config: resultset: Author select_column: id text_column: name The element name should match the relationship name. C<< $field->model_config->{select_column} >> should match the related primary column. C<< $field->model_config->{text_column} >> should match the related text column. =head2 many_to_many selection To select / deselect rows from a C relationship, you must use a multi-valued element, such as a L or a L with L set. The field's L must be set to the name of the C relationship. =head3 default_column If you want to search / associate the related table by a column other it's primary key, set C<< $field->model_config->{default_column} >>. --- element: - type: Checkboxgroup name: authors model_config: default_column: foo =head3 link_values If you want to set columns on the link table you can do so if you add a C attribute to C: --- element: - type: Checkboxgroup name: authors model_config: link_values: foo: bar =head3 additive The default implementation will first remove all related objects and set the new ones (see L). If you want to add the selected objects to the current set of objects set C in the C. --- element: - type: Checkboxgroup name: authors model_config: additive: 1 options_from_model: 0 L is set to C<0> because it will try to fetch all objects from the result class C if C is specified without a C attribute.) =head1 COMMON ARGUMENTS The following items are supported in the optional C hash-ref argument to the methods L, L and L. =over =item base If you want the method to process a particular Block element, rather than the whole form, you can pass the element as a C argument. $form->default_values( $row, { base => $formfu_element, }, ); =item nested_base If you want the method to process a particular Block element by L, you can pass the name as an argument. $form->default_values( $row, { nested_base => 'foo', }' ); =back =head1 CONFIGURATION =head2 Config options for fields The following items are supported as C options on form fields. =over =item accessor If set, C will be used as a method-name accessor on the C row object, instead of using the field name. =item ignore_if_empty If the submitted value is blank, no attempt will be made to save it to the database. =item 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. =item 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 =item label To use a column value for a form field's L. =back =head2 Config options for fields within a Repeatable block =over =item delete_if_true Intended for use on a L 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 L method names (e.g. "delete") - see L. =back =head2 Config options for Repeatable blocks =over =item 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 C to the number of extra repetitions you wish added to the end of the Repeatable block. =item 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 C. =back =head2 Config options for options_from_model The column used for the element values is set with the C value C - 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 C value C - or if not set, the first text/varchar column found in the table is used - or if one is not found, the C 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 C element: - type: Select name: foo model_config: localize_label: 1 You can set a C, which will be passed as the 1st argument to L. element: - type: Select name: foo model_config: resultset: TableClass condition: type: is_foo You can set a C, which will be passed as the 1st argument to L. C is the column-name to be passed to L, and C is the name of a key on the form L from which the value to be passed to L 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} } } }) You can set C, which will be passed as the 2nd argument to L. =head3 ENUM Column Type If the field name matches (case-insensitive) a column name with type 'ENUM' and the Schema contains enum values in C<< $resultset->column_info($name)->{extra}{list} >>, the field's options will be populated with the enum values. =head1 FAQ =head2 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 L. my $passwd = generate_passwd(); $form->add_valid( passwd => $passwd ); $form->model->update( $row ); C works for fieldnames that don't exist in the form. =head2 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 L. =head1 CAVEATS To ensure your column's inflators and deflators are called, we have to get / set values using their named methods, and not with C / C. Because of this, beware of having column names which clash with DBIx::Class built-in method-names, such as C. - It will have obviously undesirable results! =head1 REMOVED METHODS =head2 new_empty_row See C in L instead. =head2 new_empty_row_multi See C in L instead. =head2 Range constraint See C in L instead. =head1 SUPPORT Project Page: L Mailing list: L Mailing list archives: L =head1 BUGS Please submit bugs / feature requests to L (preferred) or L. =head1 GITHUB REPOSITORY This module's sourcecode is maintained in a git repository at L The project page is L =head1 SEE ALSO L, L, L =head1 AUTHOR Carl Franks =head1 CONTRIBUTORS Based on the code of C, which was contributed to by: Adam Herzog Daisuke Maki Mario Minati =head1 COPYRIGHT AND LICENSE Copyright (C) 2007 by Carl Franks Based on the original source code of L, 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. =cut multi_label.t100644001751001752 146012331707756 22201 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } has_many_repeatable.t100644001751001752 371312331707756 22155 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } opt_accessor_nested.t100644001751001752 167612331707756 22226 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } belongs_to_select.yml100644001751001752 17112331707756 22175 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- model_config: resultset: Note elements: - name: id - name: note - name: master type: Selectmany_to_many_select.t100644001751001752 253112331707756 22220 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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 ); } belongs_to_combobox.t100644001751001752 171412331707756 22214 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } opt_accessor.t100644001751001752 142212331707756 22372 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } might_have.yml100644001751001752 42612331707756 22342 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 basic_nested.t100644001751001752 535012331707756 22335 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } nested_name_accessor.t100644001751001752 227112331707756 22334 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } column_without_field.t100644001751001752 144312331707756 22413 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } MockContext.pm100644001751001752 32612331707756 21725 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/lib/HTMLFormFupackage HTMLFormFu::MockContext; use strict; use warnings; sub new { my ( $class, $args ) = @_; return bless $args, $class; } sub model { my ( $self ) = @_; return $self->{model} } 1; multi_label.yml100644001751001752 34212331707756 22515 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- elements: - type: Multi model_config: label: title elements: - type: Hidden name: id - type: Text name: name - type : Submit name: submit opt_accessor_nested.yml100644001751001752 31012331707756 22524 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit has_many_repeatable.yml100644001751001752 53512331707756 22472 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 many_to_many_select.yml100644001751001752 27012331707756 22534 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 - type: Submit name: submit many_to_many-has_many.t100644001751001752 614112331707756 22457 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } } opt_accessor.yml100644001751001752 26712331707756 22716 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit basic_nested.yml100644001751001752 120412331707756 22665 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 has_one_nested.t100644001751001752 253412331707756 22671 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } nested_create_checkbox.t100644001751001752 114012331707756 22635 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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 ); } column_without_field.yml100644001751001752 21012331707756 22720 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Submit name: submit options_from_model000755001751001752 012331707756 20255 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/tbelongs_to.t100644001751001752 224212331707756 22735 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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' ); } has_many_select.t100644001751001752 177512331707756 23057 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ] ); } empty_rows_zero.t100644001751001752 177712331707756 23172 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ); } has_many_repeatable_new.t100644001751001752 330212331707756 23020 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } many_to_many_repeatable.t100644001751001752 274612331707756 23055 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } belongs_to_select_two.yml100644001751001752 20112331707756 23060 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- model_config: resultset: TwoNote elements: - name: two_note_id - name: note - name: id type: Selectnested_repeatable_write.t100644001751001752 360612331707756 23053 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } enum_select.t100644001751001752 152112331707756 23104 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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') ); } checkbox_false2true.t100644001751001752 227412331707756 23210 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/x_roundtripuse 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' ); } checkbox_true2false.t100644001751001752 227712331707756 23213 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/x_roundtripuse 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' ); } has_one_nested.yml100644001751001752 37012331707756 23203 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 belongs_to.yml100644001751001752 43512331707756 23255 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 dbic_unique_method.yml100644001751001752 50712331707756 23422 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/constraints--- 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 dbic_unique_others.yml100644001751001752 43412331707756 23445 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/constraints--- 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 dbic_unique_column.yml100644001751001752 43712331707756 23441 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/constraints--- 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 has_many_select.yml100644001751001752 32012331707756 23356 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: addresses - type: Hidden name: count - type: Submit name: submit empty_rows_zero.yml100644001751001752 54112331707756 23474 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 has_many_combobox.t100644001751001752 177612331707756 23411 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ] ); } nested_repeatable_write.yml100644001751001752 72612331707756 23371 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 many_to_many_repeatable.yml100644001751001752 52512331707756 23364 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 has_many_repeatable_new.yml100644001751001752 63112331707756 23340 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 enum_select.yml100644001751001752 42512331707756 23424 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 might_have_missing.t100644001751001752 230712331707756 23555 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ); } many_to_many_checkboxgroup.t100644001751001752 253712331707756 23612 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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 ); } belongs_to_create_required.t100644001751001752 127712331707756 23553 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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'); might_have_delete_if_empty.t100644001751001752 226112331707756 23520 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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 ); } dbic_unique_id_field.yml100644001751001752 42112331707756 23674 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/constraints--- 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 has_many_repeatable.t100644001751001752 255312331707756 23677 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } opt_accessor_nested.t100644001751001752 154412331707756 23741 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } has_many_combobox.yml100644001751001752 32212331707756 23711 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: ComboBox name: addresses - type: Hidden name: count - type: Submit name: submit many_to_many_select.t100644001751001752 205212331707756 23737 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ] ); } many_to_many_repeatable_new.t100644001751001752 274612331707756 23726 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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++' ); } unchecked_not_null_checkbox.t100644001751001752 127012331707756 23677 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } nested_name_accessor.t100644001751001752 153212331707756 24054 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } might_have_delete_if_empty.yml100644001751001752 43412331707756 24036 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 many_to_many_checkboxgroup.yml100644001751001752 25712331707756 24125 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Checkboxgroup name: bands - type: Submit name: submit has_many_repeatable_many_new.t100644001751001752 207112331707756 24046 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } has_many_repeatable_new_date.t100644001751001752 357212331707756 24026 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } opt_accessor_nested.yml100644001751001752 31212331707756 24247 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit has_many_repeatable.yml100644001751001752 53412331707756 24212 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 many_to_many_select.yml100644001751001752 27012331707756 24255 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 - type: Submit name: submit many_to_many-has_many.t100644001751001752 652612331707756 24207 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } } many_to_many_repeatable_new.yml100644001751001752 57712331707756 24244 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 has_many_repeatable_new_empty.t100644001751001752 331112331707756 24236 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } nested_name_accessor.yml100644001751001752 15412331707756 24371 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- elements: - name: name - type: Block nested_name: foo elements: - name: value many_to_many_select_additive.yml100644001751001752 43712331707756 24412 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 has_many_repeatable_many_new.yml100644001751001752 65012331707756 24365 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 has_many_repeatable_new_date.yml100644001751001752 75712331707756 24346 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 many_to_many_select_unselected.t100644001751001752 252712331707756 24440 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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 ); } constraint_autoset.t100644001751001752 263612331707756 24541 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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, } ); DBIC000755001751001752 012331707756 21451 5ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/lib/HTML/FormFu/ConstraintUnique.pm100644001751001752 1677412331707756 23454 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/lib/HTML/FormFu/Constraint/DBICpackage HTML::FormFu::Constraint::DBIC::Unique; $HTML::FormFu::Constraint::DBIC::Unique::VERSION = '2.00'; use Moose; use MooseX::Attribute::FormFuChained; extends 'HTML::FormFu::Constraint'; use Carp qw( carp croak ); use HTML::FormFu::Util qw( DEBUG_CONSTRAINTS debug ); has model => ( is => 'rw', traits => ['FormFuChained'] ); has resultset => ( is => 'rw', traits => ['FormFuChained'] ); has column => ( is => 'rw', traits => ['FormFuChained'] ); has method_name => ( is => 'rw', traits => ['FormFuChained'] ); has self_stash_key => ( is => 'rw', traits => ['FormFuChained'] ); has others => ( is => 'rw', traits => ['FormFuChained'] ); has id_field => ( is => 'rw', traits => ['FormFuChained'] ); 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 =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. belongs_to_lookup_table.t100644001751001752 117412331707756 24605 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ); } many_to_many-has_many.yml100644001751001752 103512331707756 24533 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 has_many_repeatable_new.t100644001751001752 313512331707756 24545 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ); } many_to_many_repeatable.t100644001751001752 312012331707756 24561 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } has_many_repeatable_delete_true.t100644001751001752 332112331707756 24531 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } many_to_many_select.t100644001751001752 352612331707756 24641 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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" ); } belongs_to_combobox.t100644001751001752 250212331707756 24624 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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{
} ); has_many_repeatable_new_dependon.t100644001751001752 357512331707756 24710 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } has_many_repeatable_new_implicit.t100644001751001752 342512331707756 24720 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } belongs_to_lookup_table_combobox.t100644001751001752 306112331707756 24751 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } constraint_autoset.yml100644001751001752 55112331707756 25051 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 condition_from_stash.t100644001751001752 304212331707756 25014 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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' ); } belongs_to_lookup_table.yml100644001751001752 32312331707756 25116 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 many_to_many_repeatable.yml100644001751001752 52512331707756 25105 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 has_many_repeatable_new.yml100644001751001752 60212331707756 25057 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 has_many_repeatable_label.t100644001751001752 307712331707756 25040 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } has_many_repeatable_delete_true.yml100644001751001752 70212331707756 25047 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 many_to_many_select.yml100644001751001752 33512331707756 25152 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 belongs_to_combobox.yml100644001751001752 44112331707756 25142 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 many_to_many_select_nested.t100644001751001752 211512331707756 25301 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ] ); } has_many_repeatable_nested.t100644001751001752 367612331707756 25250 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } many_to_many_checkboxgroup.t100644001751001752 206112331707756 25323 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ] ); } has_many_repeatable_new_implicit.yml100644001751001752 60312331707756 25231 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 belongs_to_lookup_table_combobox.yml100644001751001752 56512331707756 25275 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 has_many_repeatable_new_dependon.yml100644001751001752 72312331707756 25216 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 condition_from_stash.yml100644001751001752 23612331707756 25334 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- auto_fieldset: 1 elements: - type: Select name: user model_config: resultset: User condition_from_stash: master: master_id belongs_to_config_zero.t100644001751001752 162512331707756 25325 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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 ); } has_many_repeatable_label.yml100644001751001752 61412331707756 25350 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 many_to_many_repeatable_new.t100644001751001752 330412331707756 25436 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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 ); } dbic_unique_repeatable_id_field.t100644001751001752 327212331707756 25551 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/constraintsuse 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 ); } many_to_many_select_nested.yml100644001751001752 31312331707756 25615 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 - type: Submit name: submit many_to_many_checkboxgroup.yml100644001751001752 25712331707756 25646 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Checkboxgroup name: bands - type: Submit name: submit has_many_repeatable_nested.yml100644001751001752 55712331707756 25561 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 many_to_many_checkboxgroup_read_only.t100644001751001752 254012331707756 25640 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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 ); } belongs_to_config_zero.yml100644001751001752 33112331707756 25634 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 many_to_many_repeatable_new.yml100644001751001752 57312331707756 25761 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 has_many_repeatable_new_required_when.t100644001751001752 355212331707756 25750 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } many_to_many_checkboxgroup_unselected.t100644001751001752 253612331707756 26024 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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 ); } many_to_many_checkboxgroup_restricted.t100644001751001752 307712331707756 26042 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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 } belongs_to_localize_label.t100644001751001752 124512331707756 25760 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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' ); } dbic_unique_repeatable_id_field.yml100644001751001752 65012331707756 26064 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/constraints--- 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 many_to_many_repeatable_nested.t100644001751001752 440412331707756 26131 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' ); } many_to_many_checkboxgroup_read_only.yml100644001751001752 36012331707756 26154 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 has_many_repeatable_select.t100644001751001752 660312331707756 26131 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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' ); } } has_many_repeatable_delete_true.t100644001751001752 343512331707756 26260 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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' }) ); } has_many_repeatable_many_new_exceed_max.t100644001751001752 226312331707756 26233 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/updateuse 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' ); } many_to_many_checkboxgroup_restricted.yml100644001751001752 37012331707756 26351 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 has_many_repeatable_new_required_when.yml100644001751001752 75712331707756 26272 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/update--- 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 belongs_to_localize_label.yml100644001751001752 32312331707756 26272 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 many_to_many_repeatable_nested.yml100644001751001752 55012331707756 26445 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 belongs_to_lookup_table_combobox.t100644001751001752 210612331707756 26471 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_valuesuse 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{} ); } condition_from_stash_complex.t100644001751001752 223512331707756 26546 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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' ); } has_many_repeatable_select.yml100644001751001752 64412331707756 26446 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 has_many_repeatable_delete_true.yml100644001751001752 74712331707756 26601 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 condition_from_stash_combobox.t100644001751001752 324212331707756 26706 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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' ); } belongs_to_lookup_table_combobox.yml100644001751001752 63612331707756 27015 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/default_values--- 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 many_to_many_select_restricted.t100644001751001752 321412331707756 27063 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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" ); } condition_from_stash_combobox.yml100644001751001752 24012331707756 27217 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- auto_fieldset: 1 elements: - type: ComboBox name: user model_config: resultset: User condition_from_stash: master: master_id belongs_to_config_zero_combobox.t100644001751001752 163612331707756 27217 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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 ); } many_to_many_select_restricted.yml100644001751001752 40112331707756 27374 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 belongs_to_config_zero_combobox.yml100644001751001752 33312331707756 27526 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_model--- 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 condition_from_stash_combobox_complex.t100644001751001752 231112331707756 30431 0ustar00carlcarl000000000000HTML-FormFu-Model-DBIC-2.00/t/options_from_modeluse 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' ); }