Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Dancer-Plugin-SimpleCRUD CPAN distribution.

Report information
The Basics
Id: 68177
Status: open
Priority: 0/
Queue: Dancer-Plugin-SimpleCRUD

People
Owner: Nobody in particular
Requestors: justincase [...] yopmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.04
Fixed in: (no value)

Attachments


Subject: Use acceptable_values for list view too
Download (untitled) / with headers
text/plain 803b
I noticed that acceptable_values can be used to specify field names too. I don't know if it's intentional, but it /is/ really usefully. For example, this works: acceptable_values => { field => [ [ "yes", "Yes, Sir" ], [ "no", "No, Sir" ], [ "maybe", "I'm unable to answer, Sir" ], ] } It also works really well with selectall_arrayref: acceptable_values => { WidgetID => database->selectall_arrayref('SELECT ID, Name FROM Widgets'), } Now the edit page has a nice list of widget names instead of a incomprehensible list of ID's. The bug (other than not being documented) is that it only works because of SimpleCRUD passing it to CGI::FormBuilder, and therefore currently only effects the 'Edit' view. The attached patch makes the list view work with acceptable_values too.
Subject: simplecrud-acceptable_values-list.patch
--- SimpleCRUD.pm.orig 2011-05-13 10:09:37.246425588 -0700 +++ SimpleCRUD.pm 2011-05-13 11:02:35.982164308 -0700 @@ -467,11 +467,30 @@ $sth->execute() or die "Failed to query for records in $table_name - " . database->errstr; + + # Setup transforms for columns where acceptable_values specifies alternate names + my @acceptable_values_transform; + foreach my $column ( keys %{$args->{acceptable_values}} ) { + my %replace; + foreach my $value ( @{$args->{acceptable_values}->{$column}} ) { + next unless ref $value eq "ARRAY"; + $replace{$value->[0]} = $value->[1]; + } + next unless %replace; + push( @acceptable_values_transform, { + column => $column, + transform => sub { + return '' unless $_[0]; + return $replace{$_[0]} || $_[0]; }, + }); + } + my $table = HTML::Table::FromDatabase->new ( -sth => $sth, -border => 1, -callbacks => [ + @acceptable_values_transform, { column => 'actions', transform => sub {
Download (untitled) / with headers
text/plain 227b
Apologies, I've left this bug far too long. Thanks for your patch, it looks like a useful feature, I'll get it applied and extra documentation for that option written up in the next few days and get a new release out. Cheers!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.