# -- $class->to_field($has_many_col); # foreign inputs
# $class->search_inputs; /
-use 5.006;
use strict;
use warnings;
_options_from_array _options_from_hash _to_select_or_create
);
-our @EXPORTOK =
- qw(
-
-
- );
-
-
-
our $VERSION = '.10';
=head1 NAME
Not all _to_* methods pay attention to all arguments. For example, '_to_textfield' does not look in $args->{'items'} at all.
+=over
+
=item name -- the name the element will have , this trumps the derived name.
$beer->to_field('brewery', 'readonly', {
Tell AsForm not to make hidden inputs for relationship constraints. It does
this sometimes when making foreign inputs .
+=back
=head2 to_cgi
-#
+
+=head2 unselect_element
+
+ unselect any selected elements in a HTML::Element select list widget
+
+=cut
sub unselect_element {
my ($self, $el) = @_;
#unless (ref $el eq 'HTML::Element') {
$name = $args->{name} || $obj->primary_column->name;
}
elsif ($obj = $args->{items}->[0]) {
- # cool)
- $name = $args->{name} || $obj->primary_column->name; # TODO make use meta data
+ $name = $args->{name} || $accessor || $obj->primary_column->name;
+ # TODO use meta data above maybe
}
-
else { # hiding linking related object with id in args
$obj = $self->related_class($r, $accessor)->retrieve($args->{id});
- $name = $args->{name} || $obj->primary_column->name; # TODO make use meta data
+ $name = $args->{name} || $accessor ; #$obj->primary_column->name;
+ # TODO use meta data above maybe
}
$self->_croak("_to_link_hidden has no object") unless ref $obj;
my $href = $uri || $r->config->{uri_base} . "/". $obj->table."/view/".$obj->id;
$a;
}
-
-
=head2 _to_foreign_inputs
$html_els = $class_or_obj->_to_foreign_inputs($accssr, [$fields, $accssr_meta]);
my $items = $args->{items};
my $type = ref $items;
my $proto = eval { ref $items->[0]; } || "";
- warn "Type is $type, proto is $proto\n";
+ my $optgroups = $args->{optgroups} || '';
+
+ # Array of hashes, one for each optgroup
+ if ($optgroups) {
+ my $i = 0;
+ foreach (@$optgroups) {
+ my $ogrp= HTML::Element->new('optgroup', label => $_);
+ $ogrp->push_content($self->_options_from_hash($items->[$i], $args));
+ $a->push_content($ogrp);
+ $i++;
+ }
+ }
# Single Hash
- if ($type eq 'HASH') {
+ elsif ($type eq 'HASH') {
$a->push_content($self->_options_from_hash($items, $args));
}
# Single Array
}
-
-
-
-
-
-
=head2 _options_from_objects ( $objects, $args);
Private method to makes a options out of objects. It attempts to call each
my $val = $_->{$pk};
my $opt = HTML::Element->new("option", value => $val );
$opt->attr(selected => "selected") if $selected->{$val};
- my $content = $fclass and $stringify and $fclass->can($stringify) ?
+ my $content = ($fclass and $stringify and $fclass->can($stringify)) ?
$fclass->$stringify($_) :
join(' ', @$_);
$opt->push_content( $content );
my $create = $self->to_field($col, 'foreign_inputs', $args);
$create->{'__select_or_create__'} =
$self->to_field('__select_or_create__',{ name => '__select_or_create__' , value => 1 } );
-
return ($select, $create);
}
-
-
#
# checkboxes: if no data in hand (ie called as class method), replace
sub _to_checkbox {
my ($self, $col, $args) = @_;
my $nullable = eval {self->column_nullable($col)} || 0;
-
return $self->_to_radio($col) if !ref($self) || $nullable;
my $value = $self->$col;
my $a = HTML::Element->new("input", type=> "checkbox", name => $col);