--- trunk/lib/Frey/Action.pm 2009/01/09 21:50:21 976 +++ trunk/lib/Frey/Action.pm 2009/06/04 20:30:24 1079 @@ -104,6 +104,14 @@ sub params_form { my ( $self ) = @_; + + foreach my $checkbox ( split(/\s+/, $self->params->{'frey-checkboxes'} ) ) { + next if defined $self->params->{ $checkbox }; + + $self->params->{ $checkbox } = 0; + warn "# checkbox $checkbox not ticked"; + } + my $required = $self->required('as_hash'); if ( $required ) { warn $self->class, " required params ", dump( keys %$required ) if $self->debug; @@ -134,10 +142,14 @@ my $max_value_len = 0; my @values; + my $display; my $html = ''; foreach ( @$values ) { my $v = ref($_) eq 'HASH' ? $_->{$name} : $_; + if ( $v =~ s/\t+(.+)$// ) { + $display->{$v} = $1; + } warn "## value '$v'"; push @values, $v; $max_value_len = length($v) if length($v) > $max_value_len; @@ -150,7 +162,8 @@ if ( $#values > 3 && $render !~ m{radio} ) { my $options = join("\n", map { - qq||; + my $d = $display->{$_} || $_; + qq||; } @values ); # onchange="alert(this.options[this.selectedIndex].value);" @@ -193,18 +206,11 @@ } - foreach my $checkbox ( split(/\s+/, $default->{'frey-checkboxes'} ) ) { - next if defined $default->{ $checkbox }; - - $default->{ $checkbox } = 0; - $self->params->{ $checkbox } = 0; - warn "# checkbox $checkbox not ticked"; - } - my @checkboxes; my $label_width = 1; # minimum + foreach my $name ( grep { die "$_ doesn't have meta" unless $class->can('meta'); @@ -225,7 +231,7 @@ my $value = defined $default->{$name} ? $default->{$name} : $attr->has_default ? $attr->default( $name ) : - ''; + undef; if ( ref($params_config) eq 'HASH' && defined $params_config->{$name} ) { $value = $params_config->{$name}; @@ -234,10 +240,16 @@ $default->{$name} = $params_config->[0]->{$name}; } elsif ( $attr->has_type_constraint && $attr->type_constraint->can('values') ) { $value_html = select_values( $name, $attr_type, $attr->type_constraint->values ); + } elsif ( $class->can( $name . '_available' ) ) { + my $available = eval $class . '->' . $name . '_available'; + confess $@ if $@; + $available =~ s/^\s+//gs; + $available =~ s/\s+$//gs; + $value_html = select_values( $name, $attr_type, [ split(/\n/,$available) ]); } elsif ( $attr_type =~ m{^Bool} ) { my $suffix = ''; - $suffix = ' checked' if $value; - $value_html = qq||; + $suffix = ' checked=1' if $value; + $value_html = qq||; push @checkboxes, $name; } elsif ( ! defined $value ) { $value_html = qq|undef|; # FIXME if $self->debug