You are here: Foswiki>Tasks Web>Item14390 (08 Jul 2021, MichaelDaum)Edit Attach

Item14390: FORMFIELD macro no longer accepts field title (i.e. name with spaces)

pencil
Priority: Normal
Current State: No Action Required
Released In: 2.1.7
Target Release: patch
Applies To: Engine
Component:
Branches: master Item14288 Item14380 Item14537
Reported By: LynnwoodBrown
Waiting For:
Last Change By: MichaelDaum
In earlier versions of Foswiki (pre-1.2.x), VarFORMFIELD accepted the field reference title with spaces. In recent versions, it requires the field name and fails to return value if the spaced title is used. Given that Foswiki continues to supports DataForm field naming with spaces, and for backwards compatibility, this macro should continued to accept the field spaced version of the field reference. For further consistency, it would also be nice if VarQUERY also allowed the title form of the field reference, although afaik, it never has since this macro was introduced.

Just to clarify by example, here's a sample DataForms definition:
| *Name*  | *Type* | *Size* | *Values* | *Description* | *Attributes* | *Default* | 
| Topic Title | text | 100 | | Title of the topic | H | | 

In version 1.1.10 and earlier, one could enter %FORMFIELD{"Topic Title"}% and it would properly render that field value. In 1.2.x, it returns an empty value.

-- LynnwoodBrown - 04 May 2017

I suggested a simple hack to Macros/FORMFIELD.pm which seemed to cure the problem. However I'm not sure if it's the way to go, or if we did go ahead, should it be conditional, with a "EnableSpacedFormfield" in the compatibility part of configure.
diff --git a/core/lib/Foswiki/Macros/FORMFIELD.pm b/core/lib/Foswiki/Macros/FORMFIELD.pm
index 57e4ab1..8a94475 100644
--- a/core/lib/Foswiki/Macros/FORMFIELD.pm
+++ b/core/lib/Foswiki/Macros/FORMFIELD.pm
@@ -36,6 +36,7 @@ sub FORMFIELD {
 
     my $formField = $args->{_DEFAULT};
     return '' unless defined $formField;
+    $formField =~ s/\s//g;
 
     my $text;

-- GeorgeClark - 04 May 2017

This task is clearly related to and perhaps identical to Item2097 being as spaces are not the only allowed characters in defining a field. Any change to re-enable spaces in referencing a field should also allow for other characters.

I see the point in CrawfordCurrie's comment at the end of that task, but I differ on one key point: while VarFORMFIELD does define the "name" attribute as being the "The name of a Data form field", a normal user would reasonably understand this to mean the field name as defined in DataForms - i.e. simply the value entered in the first column of the form definition - which could include spaces and other characters. The distinction between field "name" and field "title" only exist in the code and meta-data. It's not clearly explained in the documentation. If we don't provide for normalization of field references (in FORMFIELD, QUERY and perhaps even $formfield()) using regex similar to what's used to initially define the field name, then I think we also need to clarify this in the documentation. This can perhaps be accomplished simply by revising the description of "name" attribute in VarFORMFIELD to read: "The name of a Data form field (without spaces or other characters). If double-bracket link format is used in the DataForms, then use the value in the left-hand side of bracket."

-- LynnwoodBrown - 04 May 2017

I added the suggested doc. FORMFIELD is deprecated in favour of QUERY, and I'm reluctant to spend any more time on it.

-- CrawfordCurrie - 08 May 2017

Just stumbled upon it while upgrading our wiki. It is a bug, plain and simple, as what in the perl code is called title is actually called name in all the user docs, such as https://foswiki.org/System/DataForms

I am installing this patch on our production wiki (108234 topics, FORMFIELD is used 5088 times in 816 of these topics with titles with spaces in them), and see if there are no ill side effects:

--- ../wiki-2/lib/Foswiki/Macros/FORMFIELD.pm   2018-02-27 20:59:15.000000000 +0100
+++ lib/Foswiki/Macros/FORMFIELD.pm     2018-08-16 19:09:13.098878381 +0200
@@ -36,6 +36,8 @@
 
     my $formField = $args->{_DEFAULT};
     return '' unless defined $formField;
+    require Foswiki::Form;
+    $formField = Foswiki::Form::fieldTitle2FieldName($formField);
 
     my $text;
 

-- ColasNahaboo - 16 Aug 2018

Hi Colas, could you please create a new task item with your findings & patch? Feel free to check things in to be released in 2.1.7. Thanks a lot.

-- MichaelDaum - 17 Aug 2018

Yes, I'll do this!

-- ColasNahaboo - 21 Aug 2018

The patch never made it into the repos. The docu for FORMFIELD has been clarified. Closing this issue. Please reopen if you want this fixed otherwise in the core.

-- MichaelDaum - 08 Jul 2021
 
Topic revision: r13 - 08 Jul 2021, MichaelDaum - This page was cached on 06 Oct 2021 - 12:59.

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