David Hussein Brunton
Friday, May 18, 2007
  More Jifty Niftiness
A newly-discovered (by me, at least) favorite feature of my favorite Perl module: Jifty gives me a nice, easy Ajaxy way to canonicalize (read: make it lowercase) and validate (read: check for uniqueness):
package Testy::Model::Test;
use Jifty::DBI::Schema;
use Testy::Record schema {
column a => type is 'text';
column b => references Testy::Model::User;
};

sub canonicalize_a {
my ($class,$a) = @_;
return lc($a);
}

sub validate_a {
my ($class,$a) = @_;
my $unique = Testy::Model::TestCollection->new();
$unique->limit(column => 'a', operator => '=',
value => $a);
$unique->limit(column => 'b', operator => '=',
value => Jifty->web->current_user->id);
return (0, "You already said $a") if $unique->first;
return $a;
}
1;


Basically, this code automagically converts the input to lowercase (AJAX call), then presents my error message if the person has already typed in that value for a.

Plus, it's all done with as little back-and-forth as I can imagine.

Wow.
 


Links to this post:

Create a Link



<< Home
Change.

Name: David Brunton
Location: Washington, DC, United States
Archives
January 2007 / February 2007 / March 2007 / April 2007 / May 2007 / June 2007 / July 2007 / August 2007 / September 2007 / December 2007 / January 2008 / February 2008 / March 2008 / April 2008 / June 2008 / July 2008 / August 2008 /


Powered by Blogger

Subscribe to
Posts [Atom]