Skip Menu |

This queue is for tickets about the Class-DBI-AsForm CPAN distribution.

Report information
The Basics
Id: 13619
Status: new
Priority: 0/
Queue: Class-DBI-AsForm

People
Owner: Nobody in particular
Requestors: MARKSTOS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 2.41
Fixed in: (no value)



Subject: wish: smarter field size development
The module currently artifically limits its usefulness by not taking advantage of more meta data available in the database. In particular, the length of the field is very useful to know. The good news is that this is accessible through the standard DBI column_info() method and is well supported by MySQL and PostgreSQL and probably others. Unfortunately, the underlying module currently being used, Class::DBI::Plugin::Type does not give you access to this information. Once you have it, here's logic I've worked out in the past to smartly-size text and textarea inputs. sub calculate_text_field_size { # As returned from DBI's column_info my $col_metadata = shift; my $default_field_size = 20; my $col_size = $col_metadata->{COLUMN_SIZE}; my $input_type = 'text'; my $row_size; # shrink the form of the field size is smaller than our default my $size = $col_size if ($col_size < $default_field_size); # make cells slightly larger than the data in them. # this is needed to make it look "right" in some browsers. if ($col_size <= $default_field_size) { $size = $col_size+2; } # If it's larger than the default, turn it into a textarea # This prevents things like varchar(4000) from looking crazy. # The textarea is specially sized to fit the length of the field else { my $row_size = int $len/$default_field_size +1; $input_type = 'textarea'; } # We have now calculated these new values: return ($col_size,$row_size,$input_type); }
From: markstos [...] cpan.org
My Pseudo-code above turned out to be a little too "pseudo" to be of tremendous use. However, I've repaired it somewhat and put it into a related project: DBIx::AsForm. You are welcome to borrow code from as is helpful, as I did from from this module. Mark