You are here: Foswiki>Tasks Web>Item551 (22 Dec 2008, KennethLavrsen)Edit Attach

Item551: FORMFIELD does not expand documented attributes and is mssing literal tokens

pencil
Priority: Urgent
Current State: No Action Required
Released In: 1.0.0
Target Release: patch
Applies To: Engine
Component:
Branches:
Reported By: Foswiki:Main.KennethLavrsen
Waiting For:
Last Change By: KennethLavrsen
Bug originally reported as TWikibug:Item6155 by Timothe Litt

The bug is confirmed.

Transferred to Foswiki by KennethLavrsen - 22 Dec 2008


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.
  1. $name is easy to add.
  2. $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.
  3. $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.
  4. 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

Above fix should be reviewed first

The feature probably never worked.

It was documented by Sven Dowideit in TWiki SVN 15595 on TWikibug:Item4922

It probably implemented the feature for the display in the form but never for the FORMFIELD.

If it was it quickly must have stopped working again because the Render.pm does not call the Form::FieldDefinition::renderForDisplay()

But it may be better to look at the code Sven added before applying the suggested patch above.

As a minimum we should implement the literals and update the documentation for FORMFIELD. Therefore release blocker.

Duplicate of Item549

ItemTemplate edit

Summary FORMFIELD does not expand documented attributes and is mssing literal tokens
ReportedBy Foswiki:Main.KennethLavrsen
Codebase trunk
SVN Range TWiki-4.2.3, Wed, 06 Aug 2008, build 17396
AppliesTo Engine
Component
Priority Urgent
CurrentState No Action Required
WaitingFor
Checkins
TargetRelease patch
ReleasedIn 1.0.0
Topic revision: r1 - 22 Dec 2008, KennethLavrsen
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy