-sub _to_select_old_version {
- my ($self, $col, $hint) = @_;
- my $has_a_class = $hint || $self->__hasa_rels->{$col}->[0];
- my @objs = $has_a_class->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;
+sub _to_select_or_create {
+ my ($self, $col, $args) = @_;
+ $args->{name} ||= $col;
+ my $select = $self->to_field($col, 'select', $args);
+ $args->{name} = "create_" . $args->{name};
+ 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
+# with a radio button, in order to allow this field to be left
+# unspecified in search / add forms.
+#
+# Not tested
+# TODO -- make this general checkboxse
+#
+#
+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);
+ $a->attr("checked" => 'true') if $value eq 'Y';
+ return $a;
+}
+
+
+# TODO -- make this general radio butons
+#
+sub _to_radio {
+ my ($self, $col) = @_;
+ my $value = ref $self && $self->$col || '';
+ my $nullable = eval {self->column_nullable($col)} || 0;
+ my $a = HTML::Element->new("span");
+ my $ry = HTML::Element->new("input", type=> "radio", name=>$col, value=>'Y' );
+ my $rn = HTML::Element->new("input", type=> "radio", name=>$col, value=>'N' );
+ my $ru = HTML::Element->new("input", type=> "radio", name=>$col, value=>'' ) if $nullable;
+ $ry->push_content('Yes'); $rn->push_content('No');
+ $ru->push_content('n/a') if $nullable;
+ if ($value eq 'Y') { $ry->attr("checked" => 'true') }
+ elsif ($value eq 'N') { $rn->attr("checked" => 'true') }
+ elsif ($nullable) { $ru->attr("checked" => 'true') }
+ $a->push_content($ry, $rn);
+ $a->push_content($ru) if $nullable;
+ return $a;