# -- $class->to_field($has_many_col); # foreign inputs
# $class->search_inputs; /
+
use strict;
use warnings;
_options_from_objects _options_from_arrays _options_from_hashes
_options_from_array _options_from_hash _to_select_or_create
);
-
-our $VERSION = '.10';
+
+our $VERSION = '.10';
=head1 NAME
$beer->to_field($col, $args);
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', {
name => 'brewery_id'
});
-
+
=item value -- the initial value the element will have, trumps derived value
$beer->to_field('brewery', 'textfield', {
constraint => {location => 'London'},
'join' => {'brewery_tablecolumn => 'beer_obj_column'},
);
-
+
=item no_hidden_constraints --
Tell AsForm not to make hidden inputs for relationship constraints. It does
}
+
+
=head2 unselect_element
- unselect any selected elemets in a HTML::Element select list widget
+ unselect any selected elements in a HTML::Element select list widget
=cut
-
-#
sub unselect_element {
my ($self, $el) = @_;
#unless (ref $el eq 'HTML::Element') {
}
return;
}
-
-
+
=head2 _field_from_column($field, $args)
Returns an input based on the column's characteristics, namely type, or nothing.
$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
}
return $a;
+
+
}
=head2 _options_from_objects ( $objects, $args);
$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
# with a radio button, in order to allow this field to be left
foreach (keys %$element);
}
}
-
-=head2 _box($value)
+=head2 _box($value)
This functions computes the dimensions of a textarea based on the value
or the defaults.
=cut
our ($min_rows, $max_rows, $min_cols, $max_cols) = (2 => 50, 20 => 100);
-
sub _box
{
my $text = shift;