Bug: Form default values are not working for text fields
The "values" field in a form is used to define the possible range of values and to select a default value. At least, this is how it works for non-text fields.
If a field is of type "text" or "textarea", however, the default value is ignored.
This is due to the way this value is obtained in
Form::renderForEdit
. It ignores the value in the form field and pulls the value only from the meta data. I believe it would be better to do so only if there is already a form attached. If we change the form and this field exists in both forms we probably should preserve this field.
Note that a consequence of this is that if the default value for a field of type "select" is non-empty, but an empty field is possible, then the empty field is chosen incorrectly instead of the stated default value.
Note that one could argue whether the behavior for text and textarea is really a bug (albeit it seems clear to me), but the behavior for select is definitely contrary to the documentation.
There is a gotcha if this were fixed as discussed above.
Meta::getFormDef
splits the default value into separate fields and removes leading and trailing white space. This should only be done for fields other than text and textarea, as otherwise we will loose the white space information.
A fix to this problem for the situation of
SimpleTableEntryUsingForms is attached to that page (includes the handling of the splitting of fields).
Test case
Try this form:
Name: |
Type: |
Size: |
Values: |
Tooltip message: |
TopicClassification |
select |
1 |
NoDisclosure, , PublicSupported, PublicFAQ |
Classify a topic |
OperatingSystem |
checkbox+buttons |
3 |
OsHPUX, OsLinux, OsMacOS, OsSolaris, OsSunOS, OsWin |
Select the OS |
OsVersion |
textarea |
100 |
A really, really good event |
|
Another |
text |
10 |
A really, really bad event |
|
Environment
TWiki version: |
Athens, Beijing |
TWiki plugins: |
Standard |
Server OS: |
Win2K |
Web server: |
Apache |
Perl version: |
5.6.1 |
Client OS: |
Win2K |
Web Browser: |
IE6 |
--
ThomasWeigert - 16 Apr 2003
Follow up
A patch to resove this issue can be found at the feature request
ConsistentDefaultValuesForForms.
--
ThomasWeigert - 17 Apr 2003
I think my guys at work would like me to fix this
(the
ReportedBy bug field is annoying to fill in by hand every time)
--
SvenDowideit - 11 Jul 2004
a naive variation of this is commited to
SVN - Thomas - can you test this change?
289d280
< $value = $field{"value"} || "";
315d305
why is this one different in your patch?
--
SvenDowideit - 19 Jul 2004
Sven, there is a problem in that this simple patch interferes with the setting of fields through parameters, at least in Athens. I am trying to come up with an alternative, but I think we need to be careful here, as
PeterThoeny is using that feature. Can you attach the patch to this patch, and I will test this.
--
ThomasWeigert - 19 Jul 2004
I'll attach the diff later, but it is possibly going to be difficult to apply to athens. don't worry too much about breakages - I use this code extensivly at work for the companies workflow system (the Task management system for all projects). so its hugely important that it works for me
--
SvenDowideit - 19 Jul 2004
I am not trying to apply it to athens, but to the latest beta. However, I think that any enhancement must be consistent with the existing code unless it is explicitly changed. But anyway, I'll take a look at your changes to make sure that the problems that existed are not there....
--
ThomasWeigert - 19 Jul 2004
Fix record
commited to
SVN, please create a new bug report if you find a problem with it
--
SvenDowideit - 24 Jul 2004
This fix is the cause of
ReplaceTWikiFormLosesFormValues bug
--
PeterThoeny - 07 Aug 2004
This bug is now fixed as well. In
SVN
--
PeterThoeny - 07 Aug 2004