- my ($self, $col, $args ) = @_;
- use Carp qw/confess/;
- confess "No col passed to _to_textfield" unless $col;
- $args ||= {};
- my $val = $args->{value};
- my $name = $args->{name} || $col;
-
- unless (defined $val) {
- if (ref $self) {
- # Case where column inflates.
- # Input would get stringification which could be not good.
- # as in the case of Time::Piece objects
- $val = $self->can($col) ? $self->$col : ''; # in case it is a virtual column
- if (ref $val) {
- if (my $meta = $self->related_meta('',$col)) {
- if (my $code = $meta->{args}{deflate4edit} || $meta->{args}{deflate} ) {
- $val = ref $code ? &$code($val) : $val->$code;
- }
- elsif ( $val->isa('Class::DBI') ) {
- $val = $val->id;
- }
- else {
- #warn "No deflate4edit code defined for $val of type " .
- #ref $val . ". Using the stringified value in textfield..";
- }
- }
- else {
- $val = $val->id if $val->isa("Class::DBI");
- }
- }
-
- }
- else {
- $val = $args->{default};
- $val = '' unless defined $val;
- }
- }
- my $a;
- # THIS If section is neccessary or you end up with "value" for a vaiue
- # if val is
- $val = '' unless defined $val;
- $a = HTML::Element->new("input", type => "text", name => $name, value =>$val);
- $OLD_STYLE && return $a->as_HTML;
- $a;
-}
-
-
-# Old version
-#sub _to_select {
-# my ($self, $col, $hint) = @_;
-# my $fclass = $hint || $self->__hasa_rels->{$col}->[0];
-# my @objs = $fclass->retrieve_all;
-# my $a = HTML::Element->new("select", name => $col);
-# for (@objs) {
-# my $sel = HTML::Element->new("option", value => $_->id);
-# $sel->attr("selected" => "selected")
-# if ref $self
-# and eval { $_->id eq $self->$col->id };
-# $sel->push_content($_->stringify_self);
-# $a->push_content($sel);
-# }
-# $OLD_STYLE && return $a->as_HTML;
-# $a;
-#}
-
-
+ my ($self, $col, $args ) = @_;
+ use Carp qw/confess/;
+ confess "No col passed to _to_textfield" unless $col;
+ $args ||= {};
+ my $val = $args->{value};
+ my $name = $args->{name} || $col;
+
+ unless (defined $val) {
+ if (ref $self) {
+ # Case where column inflates.
+ # Input would get stringification which could be not good.
+ # as in the case of Time::Piece objects
+ $val = $self->can($col) ? $self->$col : ''; # in case it is a virtual column
+ if (ref $val) {
+ if (my $meta = $self->related_meta('',$col)) {
+ if (my $code = $meta->{args}{deflate4edit} || $meta->{args}{deflate} ) {
+ $val = ref $code ? &$code($val) : $val->$code;
+ } elsif ( $val->isa('Class::DBI') ) {
+ $val = $val->id;
+ } else {
+ #warn "No deflate4edit code defined for $val of type " .
+ #ref $val . ". Using the stringified value in textfield..";
+ }
+ } else {
+ $val = $val->id if $val->isa("Class::DBI");
+ }
+ }