Priority: Enhancement
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component: Configure
Branches: trunk
It would be useful to relate a number of checkboxes into a group in the configure ui. For example, when selecting log levels for a log. Instead of creating a hash entry for each checkbox, they could be grouped together.
# **BOOLGROUP info,warning,error,critical,alert,emergency,debug**
and if info and debug were selected, the resulting field value is:
$Foswiki::cfg{Log}{LogDispatch}{File}{levels} = 'info,debug';
I've added a BOOLGROUP type, but the issue I found is that configure doesn't allow for a value from CGI being an array. So there was no way to get back the multiple selections from the UI. The following code seems to have worked:
iff --git a/core/lib/Foswiki/Configure/Valuer.pm b/core/lib/Foswiki/Configure/Valuer.pm
index ebf6aa8..471d77e 100644
--- a/core/lib/Foswiki/Configure/Valuer.pm
+++ b/core/lib/Foswiki/Configure/Valuer.pm
@@ -115,7 +115,16 @@ sub loadCGIParams {
Carp::confess "Bad typename '$typename'" unless $typename =~ /(\w+)/;
$typename = $1; # check and untaint
my $type = Foswiki::Configure::Type::load( $typename, $keys );
- my $newval = $type->string2value( $query->param($keys) );
+
+ my $newval = '';
+ if ( $typename =~ m/GROUP/ ) {
+ my @values = $query->param($keys);
+ $newval = $type->string2value( @values );
+ }
+ else {
+ $newval = $type->string2value( $query->param($keys) );
+ }
my $xpr = '$this->{values}->' . $keys;
my $curval = eval $xpr;
if ( !$type->equals( $newval, $curval ) ) {
I tried to make it generic to permit other *GROUP type selections.
So far I've found one bug that I cannot find the reason. The "List of changes" the user is presented with to confirm, or after save, only shows the first selection, not the list. But the list is saved to the config file and the checkboxes all reflect the list contents.
The BOOLGROUP.pm module is attached.
Does this need a feature request?
--
GeorgeClark - 08 Aug 2012
No
--
CrawfordCurrie - 30 Aug 2012
I implemented a more general hook in Valuer for TWiki about a year ago, which has also been checked in here, and released in 1.1.6. (
Item12139,
distro:7b2afda8100d) (After this item's checkin; no-one missed the Foswiki version in this discussion.)
Since this is the only user of the /GROUP$/ hook, I've converted BOOLGROUP to use it, and removed the private hook. This would make it easier to port BOOLGROUP to TWiki if anyone ever needs to do so, allows BOOLGROUP to work in 1.1.6+, and it reduces the clutter in Valuer.
George is OK with the change.
--
TimotheLitt - 14 Dec 2012