[Rt-commit] r7454 - in rt/branches/3.7-EXPERIMENTAL:
html/Widgets/Form
ruz at bestpractical.com
ruz at bestpractical.com
Wed Apr 4 17:52:07 EDT 2007
Author: ruz
Date: Wed Apr 4 17:52:06 2007
New Revision: 7454
Modified:
rt/branches/3.7-EXPERIMENTAL/ (props changed)
rt/branches/3.7-EXPERIMENTAL/html/Widgets/Form/Boolean
Log:
r4887 at cubic-pc: cubic | 2007-04-04 14:48:11 +0400
* add support for Empty option in Boolean widget.
display such widget with three radio buttons and Process method returns
0, 1 or undef if value is empty
Modified: rt/branches/3.7-EXPERIMENTAL/html/Widgets/Form/Boolean
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL/html/Widgets/Form/Boolean (original)
+++ rt/branches/3.7-EXPERIMENTAL/html/Widgets/Form/Boolean Wed Apr 4 17:52:06 2007
@@ -10,10 +10,24 @@
<%METHOD InputOnly>
<%ARGS>
$Name => undef,
+
+$Empty => 0,
+$EmptyValue => 0,
+$EmptyLabel => loc( 'System default ([_1])', $EmptyValue? loc('Yes'): loc('No') ),
+
$CurrentValue => undef,
</%ARGS>
+% unless ( $Empty ) {
<input type="hidden" name="<% $Name %>" value="0" />\
-<input type="checkbox" name="<% $Name %>" <% $CurrentValue? 'checked="checked"': '' %>" />\
+<input type="checkbox" name="<% $Name %>" <% $CurrentValue? 'checked="checked"': '' %> />\
+% } else {
+<input type="radio" name="<% $Name %>" value="1" <% $CurrentValue? 'checked="checked"': '' %> />\
+<% loc('Yes') %>
+<input type="radio" name="<% $Name %>" value="0" <% defined $CurrentValue && !$CurrentValue? 'checked="checked"': '' %> />\
+<% loc('No') %>
+<input type="radio" name="<% $Name %>" value="" <% !defined $CurrentValue? 'checked="checked"': '' %> />\
+<% $EmptyLabel %>
+% }
</%METHOD>
<%METHOD Process>
@@ -21,12 +35,17 @@
$Arguments => {},
$Name => undef,
+$Empty => 0,
$CurrentValue => 0,
</%ARGS>
<%INIT>
-return $Arguments->{ $Name }? 1: 0
- if defined $Arguments->{ $Name };
-return $CurrentValue;
+my $value = $Arguments->{ $Name };
+if ( $Empty ) {
+ return undef if !defined $value || $value eq '__empty_value__';
+ return $value? 1: 0;
+} else {
+ return $value? 1: 0 if defined $value;
+ return $CurrentValue;
+}
</%INIT>
</%METHOD>
-
More information about the Rt-commit
mailing list