.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "DBIx::Class::HTMLWidget 3pm" .TH DBIx::Class::HTMLWidget 3pm "2021-01-25" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DBIx::Class::HTMLWidget \- Like FromForm but with DBIx::Class and HTML::Widget .SH "SYNOPSIS" .IX Header "SYNOPSIS" You'll need a working DBIx::Class setup and some knowledge of HTML::Widget and Catalyst. If you have no idea what I'm talking about, check the (sparse) docs of those modules. .PP .Vb 3 \& package My::Model::DBIC::Pet; \& use base \*(AqDBIx::Class\*(Aq; \& _\|_PACKAGE_\|_\->load_components(qw/HTMLWidget Core/); \& \& \& package My::Controller::Pet; # Catalyst\-style \& \& # define the widget in a sub (DRY) \& sub widget_pet { \& my ($self,$c)=@_; \& my $w=$c\->widget(\*(Aqpet\*(Aq)\->method(\*(Aqget\*(Aq); \& $w\->element(\*(AqTextfield\*(Aq,\*(Aqname\*(Aq)\->label(\*(AqName\*(Aq); \& $w\->element(\*(AqTextfield\*(Aq,\*(Aqage\*(Aq)\->label(\*(AqAge\*(Aq); \& ... \& return $w; \& } \& \& # this renders an edit form with values filled in from the DB \& sub edit : Local { \& my ($self,$c,$id)=@_; \& \& # get the object \& my $item=$c\->model(\*(AqDBIC::Pet\*(Aq)\->find($id); \& $c\->stash\->{item}=$item; \& \& # get the widget \& my $w=$self\->widget_pet($c); \& $w\->action($c\->uri_for(\*(Aqdo_edit/\*(Aq.$id)); \& \& # fill widget with data from DB \& $item\->fill_widget($w); \& } \& \& sub do_edit : Local { \& my ($self,$c,$id)=@_; \& \& # get the object from DB \& my $item=$c\->model(\*(AqDBIC::Pet\*(Aq)\->find($id); \& $c\->stash\->{item}=$item; \& \& # get the widget \& my $w=$self\->widget_pet($c); \& $w\->action($c\->uri_for(\*(Aqdo_edit/\*(Aq.$id)); \& \& # process the form parameters \& my $result = $w\->process($c\->req); \& $c\->stash\->{\*(Aqresult\*(Aq}=$result; \& \& # if there are no errors save the form values to the object \& unless ($result\->has_errors) { \& $item\->populate_from_widget($result); \& $c\->res\->redirect(\*(Aq/users/pet/\*(Aq.$id); \& } \& \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Something like Class::DBI::FromForm / Class::DBI::FromCGI but using HTML::Widget for form creation and validation and DBIx::Class as a \s-1ORM.\s0 .SS "Methods" .IX Subsection "Methods" \fIfill_widget\fR .IX Subsection "fill_widget" .PP .Vb 1 \& $dbic_object\->fill_widget($widget); .Ve .PP Fill the values of a widgets elements with the values of the \s-1DBIC\s0 object. .PP \fIpopulate_from_widget\fR .IX Subsection "populate_from_widget" .PP .Vb 2 \& my $obj=$schema\->resultset(\*(Aqpet)\->new\->populate_from_widget($result); \& my $item\->populate_from_widget($result); .Ve .PP Create or update a DBIx::Class row from a HTML::Widget::Result object .SH "CAEVATS / POSSIBLE PROBLEMS" .IX Header "CAEVATS / POSSIBLE PROBLEMS" .SS "PostgreSQL" .IX Subsection "PostgreSQL" \fI\s-1ERROR:\s0 null value in column \*(L"private\*(R" violates not-null constraint\fR .IX Subsection "ERROR: null value in column private violates not-null constraint" .PP This is a result of we trying to set a value to undef that should not be. This is typically a problem when you have a column such ass \*(L"private boolean not null\*(R". We have a special-case for this, and if you set data_type => boolean, is_nullable => 0 in your ResultSource definition, we update the value to 0 before attempting to insert or update .SH "AUTHORS" .IX Header "AUTHORS" Thomas Klausner, , http://domm.zsi.at .PP Marcus Ramberg, .PP Andreas Marienborg, .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Simon Elliott, .PP Ashley Berlin .PP Guillermo Sansovic .SH "LICENSE" .IX Header "LICENSE" This code is Copyright (c) 2003\-2006 Thomas Klausner. All rights reserved. .PP You may use and distribute this module according to the same terms that Perl is distributed under.