[Jifty-commit] r2175 - in jifty/trunk: . lib/Jifty
share/web/templates/__jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Nov 17 15:41:09 EST 2006
Author: falcone
Date: Fri Nov 17 15:41:08 2006
New Revision: 2175
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Action.pm
jifty/trunk/lib/Jifty/Manual/Actions.pod
jifty/trunk/share/web/templates/__jifty/validator.xml
Log:
r14590 at ketch: falcone | 2006-11-17 15:39:40 -0500
validator.xml - allow us to update action data just by changing it.
Without this you had to set ajax_canonicalizes on a field
in order to change it and have it propagated back.
* Show an example of a canonicalizer (lifted from the jifty presentations).
* Document the ability to frob other pieces of the action from a canonicalizer
* Add a pointer to Jifty::Manual::Actions
Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm (original)
+++ jifty/trunk/lib/Jifty/Action.pm Fri Nov 17 15:41:08 2006
@@ -36,7 +36,10 @@
See also L<Jifty::Action::Record> for data-oriented actions,
L<Jifty::Result> for how to return values from actions.
-See L<Jifty::Param::Schema> for more details.
+See L<Jifty::Param::Schema> for more details on the declarative
+syntax.
+
+See L<Jifty::Manual::Actions> for examples of using actions.
=cut
Modified: jifty/trunk/lib/Jifty/Manual/Actions.pod
==============================================================================
--- jifty/trunk/lib/Jifty/Manual/Actions.pod (original)
+++ jifty/trunk/lib/Jifty/Manual/Actions.pod Fri Nov 17 15:41:08 2006
@@ -153,13 +153,55 @@
You can also do validation in the model -- see
L<Jifty::Action::Record>
-Note that if, instead of failing, you want to automatically modify
+=head3 canonicalization
+
+If, instead of failing, you want to automatically modify
invalid content to be valid, you want a
L<canonicalizer|Jifty::Manual::Glossary/canonicalize>, not a
validator.
-Additionally, if you set C<ajax_validates> or C<ajax_canonicalizes> to
-true for an argument, then Jifty will automatically validate or
+ use Regexp::Common 'profanity_us';
+
+ sub canonicalize_body {
+ my $self = shift;
+ my $body = shift;
+ $body =~ s/$RE{profanity}/**expletives**/gi;
+ return $body;
+ }
+
+A L<canonicalizer|Jifty::Manual::Glossary/canonicalize> can also
+change other parts of the action. This lets you update the display
+dynamically in an L<AJAX|Jifty::Manual::Glossary/ajax>-enabled browser
+based on what the user has entered. For example, we can let a user
+use magic syntax to provide tags for their blog post by surrounding the
+tags with square brackets.
+
+ use Jifty::Param::Schema;
+ use Jifty::Action schema {
+ param title =>
+ label is 'Title',
+ hints is "You can provide tags like this [tag1 tag2]",
+ ajax canonicalizes;
+
+ param tags =>
+ label is 'Tags';
+ };
+
+ sub canonicalize_title {
+ my $self = shift;
+ my $value = shift;
+
+ if ($value =~ s/\[(.*?)\]//) {
+ # this clobbers, may want to merge
+ $self->argument_value( tags => $1 );
+ }
+
+ return $value;
+ }
+
+
+If you set C<ajax validates> or C<ajax canonicalizes>
+for an argument, then Jifty will automatically validate or
canonicalize it in an L<AJAX|Jifty::Manual::Glossary/ajax>-enabled
browser when the user stops typing.
Modified: jifty/trunk/share/web/templates/__jifty/validator.xml
==============================================================================
--- jifty/trunk/share/web/templates/__jifty/validator.xml (original)
+++ jifty/trunk/share/web/templates/__jifty/validator.xml Fri Nov 17 15:41:08 2006
@@ -40,7 +40,9 @@
$writer->endTag();
$writer->startTag( "canonicalizeaction", id => $action->register_name );
for my $arg ( $action->argument_names ) {
- if ( not $action->arguments->{$arg}->{ajax_canonicalizes} ) {
+ if ($ra->arguments->{$arg} eq $action->argument_value($arg) ) {
+ # if the value doesn't change, it can be ignored.
+ # canonicalizers can change other parts of the action, so we want to send all changes
$writer->emptyTag( "ignored", name => $action->form_field_name($arg) );
} elsif ( not defined $action->argument_value($arg)
or length $action->argument_value($arg) == 0 ) {
More information about the Jifty-commit
mailing list