FORMFIELD does not expand $name, $attributes, $type, $size and $definingTopic, although it is
documented
to do so.
Also, it is missing $n, $nop, $quot, $percnt & $dollar (as in formatted search). The $n is particularly annoying right now; I want to emit a
when a form field is non-null.
I looked at Render.pm, where FORMFIELD is rendered.
- $name is easy to add.
- $definingTopic - We can do this, given the (documented) restriction of only one form per topic. If the restriction is lifted, doing it efficiently would require backpointers in the metadata.
- $attributes, $type, $size - I assume the intent is to work back to the topic that defines the form. I don't think we can do this without adding metadata. Only the form defintion topic has this information. We can find that, but we don't know what revision was used when the form was attached. I think this needs to be considered and handled by someone with more time & context.
- The literal tokens are trivial.
Here is an example of why $n is useful. There are several chunks of optional attribute data that are materialized when present. They want their own paragraphs - but not whitespace when missing. Before suggesting %<nop>IF, clearly one really only wants to evaluate (much less type!) something like this once. (The example looks nonsensical because I have replaced sensitive variable names. The intent here is to show structure.)
%FORMFIELD{"LeaveType" topic="%INCLUDINGTOPIC%" format="$n%FORMFIELD{"PronounHe" topic="%INCLUDINGTOPIC%"}% took leave $value%FORMFIELD{"LeavePlace" topic="%INCLUDINGTOPIC%" format=" in $value"}%%FORMFIELD{"LeaveDate" topic="%INCLUDINGTOPIC%" format=" on $value" }%." }%
Here is a patch for items 1, 2, and 4. After due consideration, someone else needs to either fix item 3 or correct the documentation.
--- lib/TWiki/Render.pm~ 2008-09-11 23:41:58.000000000 -0400
+++ lib/TWiki/Render.pm 2008-12-22 12:53:20.000000000 -0500
@@ -842,10 +842,23 @@
$found = 1;
my $value = $field->{value};
if (length $value) {
$text = $format;
+ $text =~ s/\$name/$field->{name}/g;
+ if( $format =~ m/\$definingTopic/ ) {
+ my @defform = $meta->find('FORM');
+ my $form = $defform[0]; #TWiki only supports one form per topic
+ my $fname = $form->{name};
+ $text =~ s/\$definingTopic/$fname/g;
+
+ }
+ $text =~ s/\$n/\%BR\%/g;
+ $text =~ s/\$quot/\"/g;
+ $text =~ s/\$percnt/\%/g;
+ $text =~ s/\$dollar/\$/g;
+
$text =~ s/\$value/$value/go;
} elsif ( defined $default ) {
$text = $default;
}
last; #one hit suffices
--
TWiki:Main/TimotheLitt
- 22 Dec 2008
Good catch! Since you have check-in rights to the core, could you fix it in trunk and 4.2 branch?
--
TWiki:Main.PeterThoeny
- 23 Dec 2008
Since
$definingTopic
is not yet implemented I suggest to use a more intuitive name and to be consistent use lowercase only. May be
$formtopic
or
$formdefinitiontopic
?
--
TWiki:Main.PeterThoeny
- 23 Dec 2008
The fork used $form (See
http://foswiki.org/Tasks/Item549
), so you might want to be consistent with them. They also used a slightly different patch that uses an standard routine to expand escapes.
As for checking it in - I've never figured out the mechanics.
As I've pointed out before, you don't make it easy. And if I checkin here, I'll have to do the same work again on the fork. I don't have the bandwidth to tix things in three places (my system + two forks.) I am happy to share what I find/fix.
Hopefully someone with more bandwidth than I have can handle the checkin.
--
TWiki:Main.TimotheLitt
- 11 Jan 2009