[Jifty-commit] r2083 - jifty/trunk/lib/Jifty/Manual
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Oct 29 22:34:37 EST 2006
Author: gugod
Date: Sun Oct 29 22:34:36 2006
New Revision: 2083
Modified:
jifty/trunk/lib/Jifty/Manual/Cookbook.pod
Log:
A recipie to do ajax canonicalization.
Modified: jifty/trunk/lib/Jifty/Manual/Cookbook.pod
==============================================================================
--- jifty/trunk/lib/Jifty/Manual/Cookbook.pod (original)
+++ jifty/trunk/lib/Jifty/Manual/Cookbook.pod Sun Oct 29 22:34:36 2006
@@ -188,3 +188,33 @@
In YourApp::Record define a _guess_table_name sub that doesn't
pluralises or pluralises differently.
+
+=head2 How do I perform ajax canonicalization on a given field ?
+
+Asking user to input something in a form is really common in a web
+app. For some certain form fields you want them to have a certain
+normalized/canoncicalized form in database, and you could do a ajax
+canonicalization in Jifty very easily. Lets say your User model need a
+canonicalized C<username> field to make sure those names are n
+lowercase. All you have to do is define a metnod named
+C<canonicalize_username> your Model class, like this:
+
+ package MyApp::Model::User;
+ use base qw(MyApp::Record);
+
+ sub canonicalize_username {
+ my $class = shift;
+ my $value = shift
+ return lc($value);
+ }
+
+If the form is generated by a C<Jifty::Action::Record> -based action,
+then this is all you need to do. And that is probably 90% of the case.
+C<Jifty::Action::Record> would check if there is a method named like
+C<canonicalize_fieldname> when it is rendering form fields. If found,
+related javascript code is generated.
+
+The ajax canonicalization happenes when the input focus leaves that
+field. You would see the effect a bit latter that the value in the
+field is changed.
+
More information about the Jifty-commit
mailing list