Question
Is there a way to set the field values that will be displayed in a TWiki form dynamically, instead of hard-coding them in the Values column of the form definition? What I would like to do is use the results of a search to populate these field values. To illustrate using the Operating System example in the TWiki documentation, if a topic called OsUbix was created, in addition to OsHPUX, OsLinux, OsSolaris and OsWin, the form could then show a checkbox for OsUbix without having to manually update the form definition. If this is not possible, is there any technical reason why this functionality could not be added?
- TWiki version: 01 December 2001
- Web server: Apache
- Server OS: Linux
- Web browser: IE 4.0 / Netscape
- Client OS: Windows / Linux
--
TWikiGuest - 26 Apr 2002
Answer
Expanding variables in form definitions is currently not implemented.
You could try to hack this into the code. First, define a
%SEARCH{...}% based on
FormattedSearch that fills the value cell of the
OperatingSystem field with a comma delimited list of
Os* topics. Then, in
TWiki::Forms::renderForEdit() you need to expand the variables (indicated in red):
my %field = $meta->findOne( "FIELD", $fieldName );
my $value = $field{"value"};
$value = "" unless defined $value; # allow "0" values
$value = TWiki::handleCommonTags( $value, $TWiki::topicName );
(This code has not been tested)
--
PeterThoeny - 27 Apr 2002
Follow-up
I tried the above code change and tested it with a %SEARCH{...}% as suggested. The search evaluated fine in the form definition topic, but did not have the desired effect when editing a topic that used that form. There the search string remained unevaluated. The generated HTML was like the following:
<table border="1" cellspacing="0" cellpadding="0">
<tr><th bgcolor="#99CCCC" colspan=2><a target="FormTest2"
onClick="return launchWindow('Jonstestweb','FormTest2')"
title="Click to see details in separate window"
href="/twiki/bin/view/Jonstestweb/FormTest2">FormTest2</a> <input type="submit"
name="submitChangeForm" value=" Change " /></th
bgcolor="#99CCCC"></tr>
<tr> <th bgcolor="#99CCCC" align="right"><span title="Check one or more categories ">Dynamically Populated</span> </th
bgcolor="#99CCCC"><td align="left"> <table cellspacing="0" cellpadding="0"><tr>
<td><input type="checkbox" name="DynamicallyPopulated%SEARCH{Os[A-Za-z0-9]*
scope=topic order=topic regex=on casesensitive=on nosearch=on nototal=on format=$topic" />%SEARCH{Os[A-Za-z0-9]* scope=topic
order=topic regex=on casesensitive=on nosearch=on nototal=on format=$topic </td>
<td><input type="checkbox" name="DynamicallyPopulated}%" />}%
</td>
</tr></table>
--
TWikiGuest - 2 May 2002