Item10861: Using CALC in FormPlugin default value stopped working

pencil
Priority: Normal
Current State: No Action Required
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: FormPlugin
Branches:
Reported By: PhilippLeufke
Waiting For:
Last Change By: PhilippLeufke
IDEA! We are upgrading from Foswiki 1.0.10 to 1.1.3.

In one of our applications (for ActionTrackerPlugin), we have a date field defined, where we provide a default value which lies 1 week ahead. We use %CALC to calculate this date:

[...]

%FORMELEMENT{
name="Due"
type="date"
dateformat="%Y-%m-%d"
size="9"
title="Due date:"
default="%CALC{$FORMATTIME($TIMEADD($TODAY(),1,week),$year-$month-$day)}%"
disabled="%IF{"$WIKINAME='WikiGuest'" then="on"}%"
hint="Format: yyyy-mm-dd; empty if yet unknown."
}%

[...]

Now the problem is, that with this CALC statement, the whole form element stopped from being rendered.

I don't know, if this actually is a bug to be fixed or if it's a feature to which I have to adjust my code to make it work again...

-- PhilippLeufke - 08 Jun 2011

On my computer with FW 1.1.3 this is rendered as:
Due date:

What doesn't work?

-- ArthurClemens - 08 Jun 2011

Well, er, yes, now that you say it...

You are right. In a clean environment, there is no issue with this. But (and I'm sorry for this one...) when we put this FORMELEMENT definition into a template definition of CommentPlugin (like in Item10826), then the whole %FORMELEMENT ... gets printed in plain text:


%STARTFORM{
name="action_tracker_data"
action="save"
topic="%WEB%.ToDoList"
anchor="Action_Tracker_Data"
}%
%COMMENT{type="action_tracker_data" noform="on" templatetopic="%WEB%.%TOPIC%"}% 
%ENDFORM%

<verbatim style="display: none">
%TMPL:DEF{PROMPT:action_tracker_data}%
<div class="foswikiFormSteps">
<div class="foswikiFormStep">
<input type="hidden" name="comment_action" value="save" />
<input type="hidden" name="comment_type" value="action_tracker_data" />
<input type="hidden" name="comment_templatetopic" value="%WEB%.%TOPIC%"  />

%FORMELEMENT{
name="Due"
type="date"
dateformat="%Y-%m-%d"
size="9"
default="%CALC{$FORMATTIME($TIMEADD($TODAY(),1,week),$year-$month-$day)}%"
title="Due date:"
disabled="%IF{"$WIKINAME='WikiGuest'" then="on"}%"
hint="Format: yyyy-mm-dd; empty if undefined yet."
}%

</div>
</div>
%TMPL:END%
%POS:AFTER%%TMPL:END%
</verbatim>

Moving the FORMELEMENT out of the %TMPL:DEF block will also move it away from the <div blocks where it used to be embedded and the order of the fields gets disturbed:


%STARTFORM{
name="action_tracker_data"
action="save"
topic="%WEB%.ToDoList"
anchor="Action_Tracker_Data"
}%
%COMMENT{type="action_tracker_data" noform="on" templatetopic="%WEB%.%TOPIC%"}% 
%ENDFORM%

%FORMELEMENT{
name="Due"
type="date"
dateformat="%Y-%m-%d"
size="9"
default="%CALC{$FORMATTIME($TIMEADD($TODAY(),1,week),$year-$month-$day)}%"
title="Due date:"
disabled="%IF{"$WIKINAME='WikiGuest'" then="on"}%"
hint="Format: yyyy-mm-dd; empty if undefined yet."
}%

<verbatim style="display: none">
%TMPL:DEF{PROMPT:action_tracker_data}%
<div class="foswikiFormSteps">
<div class="foswikiFormStep">
<input type="hidden" name="comment_action" value="save" />
<input type="hidden" name="comment_type" value="action_tracker_data" />
<input type="hidden" name="comment_templatetopic" value="%WEB%.%TOPIC%"  />
</div>
</div>
%TMPL:END%
%POS:AFTER%%TMPL:END%
</verbatim>

-- PhilippLeufke - 08 Jun 2011

Now it is getting really complex. Especially SpreadSheetPlugin can behave unpredictably with other plugins.

I advice you to use DateTimePlugin for this so you can write:
default="%DATETIME{incdays="7"}%"

-- ArthurClemens - 08 Jun 2011

Thank you very much for this hint, Arthur!

I'm setting this bug to "No action required"...

-- PhilippLeufke - 08 Jun 2011

ItemTemplate edit

Summary Using CALC in FormPlugin default value stopped working
ReportedBy PhilippLeufke
Codebase 1.1.3
SVN Range
AppliesTo Extension
Component FormPlugin
Priority Normal
CurrentState No Action Required
WaitingFor
Checkins
TargetRelease n/a
ReleasedIn n/a
Topic revision: r5 - 08 Jun 2011, PhilippLeufke
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