HTML-FormFu-Model-DBIC-1.00000755000764000764 012253556454 15715 5ustar00cafrankscafranks000000000000README100644000764000764 47112253556454 16640 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00 This archive contains the distribution HTML-FormFu-Model-DBIC, version 1.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. Changes100644000764000764 1051512253556454 17313 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.001.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 LICENSE100644000764000764 4365012253556454 17033 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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, Suite 500, Boston, MA 02110-1335 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.ini100644000764000764 123412253556454 17442 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00name = HTML-FormFu-Model-DBIC author = Carl Franks license = Perl_5 copyright_holder = Carl Franks copyright_year = 2013 version = 1.00 [Prereqs] perl = 5.008001 DBD::SQLite = 0 DBIx::Class = 0.08108 HTML::FormFu = 1.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 ; for $schema->deploy() Test::Aggregate::Nested = 0.371 Test::More = 0.99 [Prereqs / DevelopRequires] Test::Pod = 0 [PodCoverageTests] [PodSyntaxTests] [PkgVersion] [NextRelease] format = %v %{yyyy-MM-dd}d [Repository] [@Basic] META.yml100644000764000764 137012253556454 17250 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00--- abstract: 'Integrate HTML::FormFu with DBIx::Class' author: - 'Carl Franks ' build_requires: DateTime::Format::SQLite: 0 Locale::Maketext: 0 SQL::Translator: 0 Test::Aggregate::Nested: 0.371 Test::More: 0.99 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 5.006, CPAN::Meta::Converter version 2.133380' 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: 1.00 List::MoreUtils: 0 Storable: 0 Task::Weaken: 0 perl: 5.008001 resources: repository: git://github.com/fireartist/HTML-FormFu-Model-DBIC.git version: 1.00 MANIFEST100644000764000764 2175712253556454 17163 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00Changes LICENSE MANIFEST META.yml Makefile.PL README dist.ini lib/HTML/FormFu/Constraint/DBIC/Unique.pm lib/HTML/FormFu/Model/DBIC.pm t-aggregate/constraints/dbic_unique.t t-aggregate/constraints/dbic_unique.yml t-aggregate/constraints/dbic_unique_column.yml t-aggregate/constraints/dbic_unique_id_field.yml t-aggregate/constraints/dbic_unique_method.yml t-aggregate/constraints/dbic_unique_others.yml t-aggregate/constraints/dbic_unique_repeatable_id_field.t t-aggregate/constraints/dbic_unique_repeatable_id_field.yml t-aggregate/create/basic.t t-aggregate/create/basic.yml t-aggregate/default_values/basic.t t-aggregate/default_values/basic.yml t-aggregate/default_values/basic_nested.t t-aggregate/default_values/basic_nested.yml t-aggregate/default_values/belongs_to_lookup_table.t t-aggregate/default_values/belongs_to_lookup_table.yml t-aggregate/default_values/belongs_to_lookup_table_combobox.t t-aggregate/default_values/belongs_to_lookup_table_combobox.yml t-aggregate/default_values/empty_rows_zero.t t-aggregate/default_values/empty_rows_zero.yml t-aggregate/default_values/has_many_combobox.t t-aggregate/default_values/has_many_combobox.yml t-aggregate/default_values/has_many_repeatable.t t-aggregate/default_values/has_many_repeatable.yml t-aggregate/default_values/has_many_repeatable_delete_true.t t-aggregate/default_values/has_many_repeatable_delete_true.yml t-aggregate/default_values/has_many_repeatable_label.t t-aggregate/default_values/has_many_repeatable_label.yml t-aggregate/default_values/has_many_repeatable_nested.t t-aggregate/default_values/has_many_repeatable_nested.yml t-aggregate/default_values/has_many_repeatable_new.t t-aggregate/default_values/has_many_repeatable_new.yml t-aggregate/default_values/has_many_select.t t-aggregate/default_values/has_many_select.yml t-aggregate/default_values/has_one.t t-aggregate/default_values/has_one.yml t-aggregate/default_values/has_one_nested.t t-aggregate/default_values/has_one_nested.yml t-aggregate/default_values/label.t t-aggregate/default_values/label.yml t-aggregate/default_values/many_to_many-has_many.t t-aggregate/default_values/many_to_many-has_many.yml t-aggregate/default_values/many_to_many_checkboxgroup.t t-aggregate/default_values/many_to_many_checkboxgroup.yml t-aggregate/default_values/many_to_many_repeatable.t t-aggregate/default_values/many_to_many_repeatable.yml t-aggregate/default_values/many_to_many_repeatable_nested.t t-aggregate/default_values/many_to_many_repeatable_nested.yml t-aggregate/default_values/many_to_many_repeatable_new.t t-aggregate/default_values/many_to_many_repeatable_new.yml t-aggregate/default_values/many_to_many_select.t t-aggregate/default_values/many_to_many_select.yml t-aggregate/default_values/many_to_many_select_nested.t t-aggregate/default_values/many_to_many_select_nested.yml t-aggregate/default_values/methods.t t-aggregate/default_values/methods.yml t-aggregate/default_values/might_have.t t-aggregate/default_values/might_have.yml t-aggregate/default_values/might_have_missing.t t-aggregate/default_values/multi_label.t t-aggregate/default_values/multi_label.yml t-aggregate/default_values/nested_name_accessor.t t-aggregate/default_values/nested_name_accessor.yml t-aggregate/default_values/opt_accessor.t t-aggregate/default_values/opt_accessor.yml t-aggregate/default_values/opt_accessor_nested.t t-aggregate/default_values/opt_accessor_nested.yml t-aggregate/multiform/0_render_page_1.t t-aggregate/multiform/1_submit_page_1.t t-aggregate/multiform/2_render_page_2.t t-aggregate/multiform/3_submit_page_2.t t-aggregate/multiform/multiform.yml t-aggregate/options_from_model/belongs_to.t t-aggregate/options_from_model/belongs_to.yml t-aggregate/options_from_model/belongs_to_combobox.t t-aggregate/options_from_model/belongs_to_combobox.yml t-aggregate/options_from_model/belongs_to_config_zero.t t-aggregate/options_from_model/belongs_to_config_zero.yml t-aggregate/options_from_model/belongs_to_config_zero_combobox.t t-aggregate/options_from_model/belongs_to_config_zero_combobox.yml t-aggregate/options_from_model/belongs_to_localize_label.t t-aggregate/options_from_model/belongs_to_localize_label.yml t-aggregate/options_from_model/condition_from_stash.t t-aggregate/options_from_model/condition_from_stash.yml t-aggregate/options_from_model/condition_from_stash_combobox.t t-aggregate/options_from_model/condition_from_stash_combobox.yml t-aggregate/options_from_model/condition_from_stash_combobox_complex.t t-aggregate/options_from_model/condition_from_stash_complex.t t-aggregate/options_from_model/constraint_autoset.t t-aggregate/options_from_model/constraint_autoset.yml t-aggregate/options_from_model/enum_select.t t-aggregate/options_from_model/enum_select.yml t-aggregate/options_from_model/has_many_repeatable_select.t t-aggregate/options_from_model/has_many_repeatable_select.yml t-aggregate/options_from_model/many_to_many_select.t t-aggregate/options_from_model/many_to_many_select.yml t-aggregate/options_from_model/many_to_many_select_restricted.t t-aggregate/options_from_model/many_to_many_select_restricted.yml t-aggregate/update/add_valid.t t-aggregate/update/basic.yml t-aggregate/update/basic_create.t t-aggregate/update/basic_update.t t-aggregate/update/belongs_to.t t-aggregate/update/belongs_to_combobox.t t-aggregate/update/belongs_to_create.t t-aggregate/update/belongs_to_create_required.t t-aggregate/update/belongs_to_lookup_table_combobox.t t-aggregate/update/belongs_to_lookup_table_combobox.yml t-aggregate/update/belongs_to_select.t t-aggregate/update/belongs_to_select.yml t-aggregate/update/belongs_to_select_two.yml t-aggregate/update/column_without_field.t t-aggregate/update/column_without_field.yml t-aggregate/update/has_many_repeatable.t t-aggregate/update/has_many_repeatable.yml t-aggregate/update/has_many_repeatable_delete_true.t t-aggregate/update/has_many_repeatable_delete_true.yml t-aggregate/update/has_many_repeatable_many_new.t t-aggregate/update/has_many_repeatable_many_new.yml t-aggregate/update/has_many_repeatable_many_new_exceed_max.t t-aggregate/update/has_many_repeatable_new.t t-aggregate/update/has_many_repeatable_new.yml t-aggregate/update/has_many_repeatable_new_date.t t-aggregate/update/has_many_repeatable_new_date.yml t-aggregate/update/has_many_repeatable_new_dependon.t t-aggregate/update/has_many_repeatable_new_dependon.yml t-aggregate/update/has_many_repeatable_new_empty.t t-aggregate/update/has_many_repeatable_new_implicit.t t-aggregate/update/has_many_repeatable_new_implicit.yml t-aggregate/update/has_many_repeatable_new_required_when.t t-aggregate/update/has_many_repeatable_new_required_when.yml t-aggregate/update/has_one.t t-aggregate/update/has_one.yml t-aggregate/update/has_one_create.t t-aggregate/update/has_one_no_id.t t-aggregate/update/has_one_no_id.yml t-aggregate/update/has_one_select.t t-aggregate/update/has_one_select.yml t-aggregate/update/ignore_if_empty.t t-aggregate/update/ignore_if_empty.yml t-aggregate/update/many_to_many-has_many.t t-aggregate/update/many_to_many_checkboxgroup.t t-aggregate/update/many_to_many_checkboxgroup.yml t-aggregate/update/many_to_many_checkboxgroup_read_only.t t-aggregate/update/many_to_many_checkboxgroup_read_only.yml t-aggregate/update/many_to_many_checkboxgroup_restricted.t t-aggregate/update/many_to_many_checkboxgroup_restricted.yml t-aggregate/update/many_to_many_checkboxgroup_unselected.t t-aggregate/update/many_to_many_repeatable.t t-aggregate/update/many_to_many_repeatable.yml t-aggregate/update/many_to_many_repeatable_new.t t-aggregate/update/many_to_many_repeatable_new.yml t-aggregate/update/many_to_many_select.t t-aggregate/update/many_to_many_select.yml t-aggregate/update/many_to_many_select_additive.yml t-aggregate/update/many_to_many_select_unselected.t t-aggregate/update/methods.t t-aggregate/update/methods.yml t-aggregate/update/might_have.t t-aggregate/update/might_have.yml t-aggregate/update/might_have_create.t t-aggregate/update/might_have_delete_if_empty.t t-aggregate/update/might_have_delete_if_empty.yml t-aggregate/update/nested.yml t-aggregate/update/nested_create.t t-aggregate/update/nested_create_checkbox.t t-aggregate/update/nested_name_accessor.t t-aggregate/update/nested_repeatable_write.t t-aggregate/update/nested_repeatable_write.yml t-aggregate/update/null_if_empty.t t-aggregate/update/null_if_empty.yml t-aggregate/update/opt_accessor.t t-aggregate/update/opt_accessor.yml t-aggregate/update/opt_accessor_nested.t t-aggregate/update/opt_accessor_nested.yml t-aggregate/update/unchecked_not_null_checkbox.t t-aggregate/x_roundtrip/checkbox.yml t-aggregate/x_roundtrip/checkbox_false2true.t t-aggregate/x_roundtrip/checkbox_true2false.t t/aggregate.t 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 Makefile.PL100644000764000764 302012253556454 17743 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00 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" => "1.00", "List::MoreUtils" => 0, "Storable" => 0, "Task::Weaken" => 0 }, "TEST_REQUIRES" => { "DateTime::Format::SQLite" => 0, "Locale::Maketext" => 0, "SQL::Translator" => 0, "Test::Aggregate::Nested" => "0.371", "Test::More" => "0.99" }, "VERSION" => "1.00", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "DBD::SQLite" => 0, "DBIx::Class" => "0.08108", "DateTime::Format::SQLite" => 0, "HTML::FormFu" => "1.00", "List::MoreUtils" => 0, "Locale::Maketext" => 0, "SQL::Translator" => 0, "Storable" => 0, "Task::Weaken" => 0, "Test::Aggregate::Nested" => "0.371", "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); t000755000764000764 012253556454 16101 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00aggregate.t100644000764000764 25612253556454 20337 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/tuse strict; use warnings; use Test::More; use Test::Aggregate::Nested; Test::Aggregate::Nested->new( { dirs => 't-aggregate', # verbose => 1, } )->run; lib000755000764000764 012253556454 16647 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/tMySchema.pm100644000764000764 15612253556454 21035 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t/libpackage MySchema; use strict; use warnings; use base 'DBIx::Class::Schema'; __PACKAGE__->load_classes; 1; DBICTestLib.pm100644000764000764 103412253556454 21333 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; MySchema000755000764000764 012253556454 20355 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t/libBand.pm100644000764000764 111612253556454 21716 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; Note.pm100644000764000764 70612253556454 21743 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; Task.pm100644000764000764 101712253556454 21754 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; Type.pm100644000764000764 51412253556454 21754 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; User.pm100644000764000764 302512253556454 21771 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; Type2.pm100644000764000764 51612253556454 22040 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; HTMLFormFu000755000764000764 012253556454 20532 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t/libI18N.pm100644000764000764 26712253556454 21674 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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.pm100644000764000764 455512253556454 22317 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; MySchemaRS000755000764000764 012253556454 20622 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t/libUser.pm100644000764000764 100712253556454 22234 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; Address.pm100644000764000764 101512253556454 22435 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; HasMany.pm100644000764000764 71412253556454 22375 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; Manager.pm100644000764000764 62212253556454 22405 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; TwoNote.pm100644000764000764 74712253556454 22442 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; Schedule.pm100644000764000764 114412253556454 22607 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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.pm100644000764000764 111612253556454 22555 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; create000755000764000764 012253556454 21270 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregatebasic.t100644000764000764 163012253556454 22676 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ) } I18N000755000764000764 012253556454 21211 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t/lib/HTMLFormFuen.pm100644000764000764 24312253556454 22270 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; basic.yml100644000764000764 122312253556454 23232 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 update000755000764000764 012253556454 21307 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregatebasic.yml100644000764000764 151212253556454 23252 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_one.t100644000764000764 214212253556454 23247 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } methods.t100644000764000764 217512253556454 23304 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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-aggregate/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); } Model000755000764000764 012253556454 21406 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/lib/HTML/FormFuDBIC.pm100644000764000764 15106312253556454 22653 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/lib/HTML/FormFu/Modelpackage HTML::FormFu::Model::DBIC; { $HTML::FormFu::Model::DBIC::VERSION = '1.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 ManagedBand.pm100644000764000764 116712253556454 23201 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; nested.yml100644000764000764 135712253556454 23462 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 add_valid.t100644000764000764 171612253556454 23550 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_one.yml100644000764000764 42212253556454 23564 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 23712253556454 23617 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- elements: - type: Text name: method_test - type: Select name: method_select_test - type: Checkbox name: method_checkbox_test MockContext.pm100644000764000764 32612253556454 23447 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.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; belongs_to.t100644000764000764 154012253556454 23767 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 207012253556454 23746 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } basic_create.t100644000764000764 302212253556454 24235 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } basic_update.t100644000764000764 301312253556454 24254 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } might_have.yml100644000764000764 42612253556454 24267 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 opt_accessor.t100644000764000764 163112253556454 24321 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } default_values000755000764000764 012253556454 23030 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregatebasic.t100644000764000764 601612253556454 24441 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } label.t100644000764000764 141212253556454 24432 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_one_no_id.t100644000764000764 201212253556454 24413 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } nested_create.t100644000764000764 214112253556454 24437 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 233112253556454 24501 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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, "" ); } multiform000755000764000764 012253556454 22043 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregatemultiform.yml100644000764000764 66512253556454 24733 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/multiform--- id: form auto_fieldset: 1 crypt_args: -key: 'my secret' forms: # form 1 - indicator: foo elements: - name: foo - type: Submit name: submit # form 2 - indicator: bar elements: - name: bar - type: Submit name: submit # form 3 - indicator: baz elements: - name: baz - type: Submit name: submit has_one_create.t100644000764000764 200412253556454 24567 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_one_select.t100755000764000764 301012253556454 24604 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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-aggregate/update/has_one_select.yml'); $form->model->default_values($row); $form->process; like($form, qr/value="1" selected=/); } opt_accessor.yml100644000764000764 26712253556454 24643 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit basic.yml100644000764000764 132712253556454 24777 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_one.t100644000764000764 227712253556454 25001 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } label.yml100644000764000764 25512253556454 24754 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name model_config: label: title - type: Submit name: submit methods.t100644000764000764 104612253556454 25021 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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" ); } has_one_no_id.yml100644000764000764 34512253556454 24740 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 ignore_if_empty.t100644000764000764 150112253556454 25010 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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, " " ); } null_if_empty.yml100644000764000764 24212253556454 25016 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- model_config: resultset: User elements: - type: Text name: name - type: Text name: title model_config: null_if_empty: 1 x_roundtrip000755000764000764 012253556454 22402 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregatecheckbox.yml100644000764000764 12012253556454 25024 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/x_roundtrip--- elements: - name: id - type: Checkbox name: checkbox_col constraints000755000764000764 012253556454 22374 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregatedbic_unique.t100644000764000764 1033612253556454 25233 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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-aggregate/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-aggregate/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-aggregate/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-aggregate/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.yml100644000764000764 32312253556454 25123 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_one.yml100644000764000764 34512253556454 25311 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 15012253556454 25332 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/default_values--- elements: - type: Text name: method_test - type: Select name: method_select_testbelongs_to_create.t100644000764000764 127012253556454 25312 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 252212253556454 25327 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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-aggregate/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'); } ignore_if_empty.yml100644000764000764 17412253556454 25333 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- model_config: resultset: User elements: - type: Password name: name model_config: ignore_if_empty: 1 might_have_create.t100644000764000764 216612253556454 25277 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.yml100644000764000764 37312253556454 25531 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 245712253556454 25500 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } 0_render_page_1.t100644000764000764 121112253556454 25275 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/multiformuse strict; use warnings; use Test::More; eval { require HTML::FormFu::MultiForm }; if ($@) { plan skip_all => 'HTML::FormFu::MultiForm required'; die $!; } plan tests => 2; my $multi = HTML::FormFu::MultiForm->new({ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } }); $multi->load_config_file('t-aggregate/multiform/multiform.yml'); $multi->process; my $html = <
HTML is( "$multi", $html ); my $form = $multi->current_form; is( "$form", $html ); 1_submit_page_1.t100644000764000764 103112253556454 25322 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/multiformuse strict; use warnings; use Test::More; eval { require HTML::FormFu::MultiForm }; if ($@) { plan skip_all => 'HTML::FormFu::MultiForm required'; die $!; } plan tests => 2; my $multi = HTML::FormFu::MultiForm->new; $multi->load_config_file('t-aggregate/multiform/multiform.yml'); $multi->process( { foo => 'abc', submit => 'Submit', } ); my $form = $multi->current_form; ok( $form->submitted_and_valid ); is_deeply( $form->params, { foo => 'abc', submit => 'Submit', } ); 2_render_page_2.t100644000764000764 276012253556454 25312 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/multiformuse strict; use warnings; use Test::More; eval { require HTML::FormFu::MultiForm }; if ($@) { plan skip_all => 'HTML::FormFu::MultiForm required'; die 'HTML::FormFu::MultiForm required'; } eval { require Crypt::CBC }; if ($@) { plan skip_all => 'Crypt::CBC required'; die 'Crypt::CBC required'; } eval { require YAML::Syck }; if ($@) { plan skip_all => 'YAML::Syck required'; die 'YAML::Syck required'; } plan tests => 7; use Crypt::CBC (); use Storable qw/ thaw /; use YAML::Syck qw/ LoadFile /; my $yaml_file = 't-aggregate/multiform/multiform.yml'; my $multi = HTML::FormFu::MultiForm->new({ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } }); $multi->load_config_file($yaml_file); $multi->process( { foo => 'abc', submit => 'Submit', } ); ok( $multi->current_form->submitted_and_valid ); like( "$multi", qr|| ); # internals alert! # decrypt the hidden value, and check it contains the expected data my $form2 = $multi->next_form; my $value = $form2->get_field( { name => $multi->default_multiform_hidden_name } )->default; my $yaml = LoadFile($yaml_file); my $cbc = Crypt::CBC->new( %{ $yaml->{crypt_args} } ); my $decrypted = $cbc->decrypt_hex($value); my $data = thaw($decrypted); is( $data->{current_form}, 2 ); ok( grep { $_ eq 'foo' } @{ $data->{valid_names} } ); ok( grep { $_ eq 'submit' } @{ $data->{valid_names} } ); is( $data->{params}{foo}, 'abc' ); is( $data->{params}{submit}, 'Submit' ); 3_submit_page_2.t100644000764000764 253212253556454 25334 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/multiformuse strict; use warnings; use Test::More; eval { require HTML::FormFu::MultiForm }; if ($@) { plan skip_all => 'HTML::FormFu::MultiForm required'; die $!; } plan tests => 6; # submit form 1 my $yaml_file = 't-aggregate/multiform/multiform.yml'; my $form2_hidden_value; { my $multi = HTML::FormFu::MultiForm->new; $multi->load_config_file($yaml_file); $multi->process( { foo => 'abc', submit => 'Submit', } ); ok( $multi->current_form->submitted_and_valid ); my $form2 = $multi->next_form; my $hidden_field = $form2->get_field( { name => $multi->default_multiform_hidden_name } ); $form2_hidden_value = $hidden_field->default; } # submit form 2 { my $multi = HTML::FormFu::MultiForm->new({ tt_args => { INCLUDE_PATH => 'share/templates/tt/xhtml' } }); $multi->load_config_file($yaml_file); $multi->process( { $multi->default_multiform_hidden_name => $form2_hidden_value, bar => 'def', submit => 'Submit', } ); my $form = $multi->current_form; ok( $form->submitted_and_valid ); my $params = $form->params; is( $params->{foo}, 'abc' ); is( $params->{bar}, 'def' ); is( $params->{submit}, 'Submit' ); # does form 3 render ok? like( "$multi", qr|| ); } multi_label.t100644000764000764 147212253556454 25652 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } belongs_to_combobox.t100644000764000764 172612253556454 25665 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } belongs_to_select.yml100644000764000764 17112253556454 25643 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- model_config: resultset: Note elements: - name: id - name: note - name: master type: Selecthas_many_repeatable.t100644000764000764 372512253556454 25626 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } many_to_many_select.t100644000764000764 254312253556454 25671 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } opt_accessor_nested.t100644000764000764 171012253556454 25661 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } DBIC000755000764000764 012253556454 23173 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/lib/HTML/FormFu/ConstraintUnique.pm100644000764000764 1666212253556454 25172 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/lib/HTML/FormFu/Constraint/DBICpackage HTML::FormFu::Constraint::DBIC::Unique; { $HTML::FormFu::Constraint::DBIC::Unique::VERSION = '1.00'; } use Moose; extends 'HTML::FormFu::Constraint'; use Carp qw( carp croak ); use HTML::FormFu::Util qw( DEBUG_CONSTRAINTS debug ); has model => ( is => 'rw', traits => ['Chained'] ); has resultset => ( is => 'rw', traits => ['Chained'] ); has column => ( is => 'rw', traits => ['Chained'] ); has method_name => ( is => 'rw', traits => ['Chained'] ); has self_stash_key => ( is => 'rw', traits => ['Chained'] ); has others => ( is => 'rw', traits => ['Chained'] ); has id_field => ( is => 'rw', traits => ['Chained'] ); sub constrain_value { my ( $self, $value ) = @_; return 1 if !defined $value || $value eq ''; for (qw/ resultset /) { if ( !defined $self->$_ ) { # warn and die, as errors are swallowed by HTML-FormFu carp "'$_' is not defined"; croak "'$_' is not defined"; } } # get stash my $stash = $self->form->stash; my $schema; if ( defined $stash->{schema} ) { $schema = $stash->{schema}; } elsif ( defined $stash->{context} && defined $self->model ) { $schema = $stash->{context}->model( $self->model ); } elsif ( defined $stash->{context} ) { $schema = $stash->{context}->model; } if ( !defined $schema ) { # warn and die, as errors are swallowed by HTML-FormFu carp 'could not find DBIC schema'; croak 'could not find DBIC schema'; } my $resultset = $schema->resultset( $self->resultset ); if ( !defined $resultset ) { # warn and die, as errors are swallowed by HTML-FormFu carp 'could not find DBIC resultset'; croak 'could not find DBIC resultset'; } if ( my $method_name = $self->method_name ) { # warn "using $method_name to look for $value"; # need to be able to tell $method_name about record on the form stash my $pk_val; if ( defined( my $self_stash_key = $self->self_stash_key ) ) { if ( defined( my $self_stash = $stash->{ $self_stash_key } ) ) { my ($pk) = $resultset->result_source->primary_columns; $pk_val = $self_stash->$pk; } } return $resultset->$method_name( $value, $pk_val ); } else { my $column = $self->column || $self->parent->name; my %others; if ( $self->others ) { my @others = ref $self->others ? @{ $self->others } : $self->others; my $params = $self->form->input; %others = grep { defined && length } map { $_ => $self->get_nested_hash_value( $params, $_ ) } @others; } my $existing_row = eval { $resultset->find( { %others, $column => $value } ); }; if ( my $error = $@ ) { # warn and die, as errors are swallowed by HTML-FormFu carp $error; croak $error; } # if a row exists, first check whether it matches a known object on the # form stash if ( $existing_row && defined( my $self_stash_key = $self->self_stash_key ) ) { if ( defined( my $self_stash = $stash->{ $self_stash_key } ) ) { my ($pk) = $resultset->result_source->primary_columns; if ( $existing_row->$pk eq $self_stash->$pk ) { return 1; } } } elsif ( $existing_row && defined (my $id_field = $self->id_field ) ) { my $value = $self->get_nested_hash_value( $self->form->input, $id_field ); if ( defined $value && length $value ) { my ($pk) = $resultset->result_source->primary_columns; return ($existing_row->$pk eq $value); } } return !$existing_row; } } after repeatable_repeat => sub { my ( $self, $repeatable, $new_block ) = @_; # rename any 'id_field' fields if ( my $id_field = $self->id_field ) { my $block_fields = $new_block->get_fields; my $field = $repeatable->get_field_with_original_name( $id_field, $block_fields ); if ( defined $field ) { DEBUG_CONSTRAINTS && debug( sprintf "Repeatable renaming constraint 'id_field' '%s' to '%s'", $id_field, $field->nested_name, ); $self->id_field( $field->nested_name ); } } }; 1; __END__ =head1 NAME HTML::FormFu::Constraint::DBIC::Unique =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. basic_nested.t100644000764000764 536212253556454 26006 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } might_have.yml100644000764000764 42612253556454 26010 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 opt_accessor.t100644000764000764 143412253556454 26043 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } column_without_field.t100644000764000764 145512253556454 26064 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } nested_name_accessor.t100644000764000764 230312253556454 25776 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } multi_label.yml100644000764000764 34212253556454 26163 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/default_values--- elements: - type: Multi model_config: label: title elements: - type: Hidden name: id - type: Text name: name - type : Submit name: submit has_many_repeatable.yml100644000764000764 53512253556454 26140 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-has_many.t100644000764000764 615312253556454 26130 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } } many_to_many_select.yml100644000764000764 27012253556454 26202 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 - type: Submit name: submit opt_accessor_nested.yml100644000764000764 31012253556454 26172 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- auto_fieldset: nested_name: foo elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit basic_nested.yml100644000764000764 120412253556454 26333 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 254612253556454 26342 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } opt_accessor.yml100644000764000764 26712253556454 26364 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: fullname model_config: accessor: fullname - type: Submit name: submit options_from_model000755000764000764 012253556454 23723 5ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregatebelongs_to.t100644000764000764 225412253556454 26406 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } column_without_field.yml100644000764000764 21012253556454 26366 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: text_col - type: Submit name: submit nested_create_checkbox.t100644000764000764 115212253556454 26306 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } empty_rows_zero.t100644000764000764 201112253556454 26616 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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_select.t100644000764000764 200712253556454 26512 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ] ); } enum_select.t100644000764000764 153312253556454 26555 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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') ); } belongs_to_select_two.yml100644000764000764 20112253556454 26526 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- model_config: resultset: TwoNote elements: - name: two_note_id - name: note - name: id type: Selecthas_many_repeatable_new.t100644000764000764 331412253556454 26471 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 276012253556454 26517 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } nested_repeatable_write.t100644000764000764 362012253556454 26515 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_one_nested.yml100644000764000764 37012253556454 26651 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 43512253556454 26723 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 checkbox_false2true.t100644000764000764 230612253556454 26652 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 231112253556454 26646 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } dbic_unique_column.yml100644000764000764 43712253556454 27107 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 dbic_unique_method.yml100644000764000764 50712253556454 27070 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 43412253556454 27113 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 empty_rows_zero.yml100644000764000764 54112253556454 27142 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 201012253556454 27035 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ] ); } has_many_select.yml100644000764000764 32012253556454 27024 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 enum_select.yml100644000764000764 42512253556454 27072 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable_new.yml100644000764000764 63112253556454 27006 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 many_to_many_repeatable.yml100644000764000764 52512253556454 27032 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 nested_repeatable_write.yml100644000764000764 72612253556454 27037 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 might_have_missing.t100644000764000764 232112253556454 27217 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } belongs_to_create_required.t100644000764000764 127712253556454 27221 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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'); many_to_many_checkboxgroup.t100644000764000764 255112253556454 27254 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } might_have_delete_if_empty.t100644000764000764 227312253556454 27171 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.yml100644000764000764 42112253556454 27342 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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_combobox.yml100644000764000764 32212253556454 27357 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable.t100644000764000764 256512253556454 27350 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } many_to_many_select.t100644000764000764 206412253556454 27410 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ] ); } opt_accessor_nested.t100644000764000764 155612253556454 27412 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } many_to_many_repeatable_new.t100644000764000764 276012253556454 27370 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 130212253556454 27341 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 154412253556454 27525 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_many_repeatable_many_new.t100644000764000764 210312253556454 27510 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 360412253556454 27470 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } many_to_many_checkboxgroup.yml100644000764000764 25712253556454 27573 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/update--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Checkboxgroup name: bands - type: Submit name: submit might_have_delete_if_empty.yml100644000764000764 43412253556454 27504 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable.yml100644000764000764 53412253556454 27660 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-has_many.t100644000764000764 654012253556454 27651 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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_select.yml100644000764000764 27012253556454 27723 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Select name: bands multiple: 1 - type: Submit name: submit opt_accessor_nested.yml100644000764000764 31212253556454 27715 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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_new_empty.t100644000764000764 332312253556454 27707 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } many_to_many_repeatable_new.yml100644000764000764 57712253556454 27712 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 nested_name_accessor.yml100644000764000764 15412253556454 30037 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/default_values--- elements: - name: name - type: Block nested_name: foo elements: - name: value constraint_autoset.t100644000764000764 265012253556454 30203 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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, } ); has_many_repeatable_many_new.yml100644000764000764 65012253556454 30033 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 75712253556454 30014 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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_additive.yml100644000764000764 43712253556454 30060 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 many_to_many_select_unselected.t100644000764000764 254112253556454 30102 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } belongs_to_lookup_table.t100644000764000764 120612253556454 30247 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } has_many_repeatable_new.t100644000764000764 314712253556454 30216 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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-has_many.yml100644000764000764 103512253556454 30201 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 many_to_many_repeatable.t100644000764000764 313212253556454 30232 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } belongs_to_combobox.t100644000764000764 251412253556454 30275 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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{
} ); many_to_many_select.t100644000764000764 354012253556454 30303 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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" ); } has_many_repeatable_delete_true.t100644000764000764 333312253556454 30202 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } condition_from_stash.t100644000764000764 306612253556454 30470 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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-aggregate/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' ); } constraint_autoset.yml100644000764000764 55112253556454 30517 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 belongs_to_lookup_table_combobox.t100644000764000764 307312253556454 30422 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_many_repeatable_new_dependon.t100644000764000764 360712253556454 30352 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 343712253556454 30371 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.yml100644000764000764 32312253556454 30564 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable_label.t100644000764000764 311112253556454 30473 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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_new.yml100644000764000764 60212253556454 30525 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 many_to_many_repeatable.yml100644000764000764 52512253556454 30553 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 belongs_to_combobox.yml100644000764000764 44112253556454 30610 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 33512253556454 30620 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable_delete_true.yml100644000764000764 70212253556454 30515 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable_nested.t100644000764000764 371012253556454 30703 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 207312253556454 30774 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ] ); } many_to_many_select_nested.t100644000764000764 212712253556454 30752 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ] ); } belongs_to_config_zero.t100644000764000764 163712253556454 30776 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } condition_from_stash.yml100644000764000764 23612253556454 31002 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/options_from_model--- auto_fieldset: 1 elements: - type: Select name: user model_config: resultset: User condition_from_stash: master: master_id belongs_to_lookup_table_combobox.yml100644000764000764 56512253556454 30743 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 72312253556454 30664 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable_new_implicit.yml100644000764000764 60312253556454 30677 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable_label.yml100644000764000764 61412253556454 31016 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 331612253556454 31107 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.t100644000764000764 330412253556454 31213 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } has_many_repeatable_nested.yml100644000764000764 55712253556454 31227 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 25712253556454 31314 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/default_values--- auto_fieldset: 1 elements: - type: Hidden name: id - type: Text name: name - type: Checkboxgroup name: bands - type: Submit name: submit many_to_many_select_nested.yml100644000764000764 31312253556454 31263 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 belongs_to_config_zero.yml100644000764000764 33112253556454 31302 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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_checkboxgroup_read_only.t100644000764000764 255212253556454 31311 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } many_to_many_repeatable_new.yml100644000764000764 57312253556454 31427 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 belongs_to_localize_label.t100644000764000764 125712253556454 31431 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_many_repeatable_new_required_when.t100644000764000764 356412253556454 31421 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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_restricted.t100644000764000764 311112253556454 31475 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 } many_to_many_checkboxgroup_unselected.t100644000764000764 255012253556454 31466 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } dbic_unique_repeatable_id_field.yml100644000764000764 65012253556454 31532 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 441612253556454 31602 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_many_repeatable_select.t100644000764000764 661512253556454 31602 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } } many_to_many_checkboxgroup_read_only.yml100644000764000764 36012253556454 31622 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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_delete_true.t100644000764000764 344712253556454 31731 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' }) ); } belongs_to_localize_label.yml100644000764000764 32312253556454 31740 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 has_many_repeatable_many_new_exceed_max.t100644000764000764 227512253556454 31704 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); } has_many_repeatable_new_required_when.yml100644000764000764 75712253556454 31740 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 many_to_many_checkboxgroup_restricted.yml100644000764000764 37012253556454 32017 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 belongs_to_lookup_table_combobox.t100644000764000764 212012253556454 32133 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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{} ); } many_to_many_repeatable_nested.yml100644000764000764 55012253556454 32113 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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 condition_from_stash_complex.t100644000764000764 224712253556454 32217 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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.yml100644000764000764 64412253556454 32114 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 74712253556454 32247 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 326612253556454 32362 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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-aggregate/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.yml100644000764000764 63612253556454 32463 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 322612253556454 32534 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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" ); } belongs_to_config_zero_combobox.t100644000764000764 165012253556454 32661 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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 ); } condition_from_stash_combobox.yml100644000764000764 24012253556454 32665 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/options_from_model--- auto_fieldset: 1 elements: - type: ComboBox name: user model_config: resultset: User condition_from_stash: master: master_id many_to_many_select_restricted.yml100644000764000764 40112253556454 33042 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.yml100644000764000764 33312253556455 33175 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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.t100644000764000764 232312253556455 34103 0ustar00cafrankscafranks000000000000HTML-FormFu-Model-DBIC-1.00/t-aggregate/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-aggregate/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' ); }