[Rt-commit] rt branch, 4.4/select-cf-hide-invalid-empty-values, created. rt-4.2.5-208-ga67e05e

? sunnavy sunnavy at bestpractical.com
Tue Oct 14 12:32:48 EDT 2014


The branch, 4.4/select-cf-hide-invalid-empty-values has been created
        at  a67e05ea491eeab2c2dea5cc693cee1884e96716 (commit)

- Log -----------------------------------------------------------------
commit a67e05ea491eeab2c2dea5cc693cee1884e96716
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 12 20:31:22 2014 +0800

    hide "(no value)" from select cfs if it doesn't match pattern and has default values
    
    the reason we require existing "default values" here is sometimes we want to
    force users to select a value(i.e. no default values), even "(no value)" is not
    valid(doesn't math the pattern), it's a good initial state for select input
    in this case. consider a "Perl version" cf in a bug report.
    
    but we should always show "(no value)" on cf admin page so admins can delete
    default values.

diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html
index fb0a6f2..8610cec 100644
--- a/share/html/Admin/CustomFields/Modify.html
+++ b/share/html/Admin/CustomFields/Modify.html
@@ -130,7 +130,7 @@ jQuery( function() {
 % if ( $CustomFieldObj->SupportDefaultValues ) {
 <tr class="edit_default_values"><td class="label"><&|/l, $CustomFieldObj->MaxValues &>Default [numerate,_1,value,values]</&></td>
 <td>
-<& /Elements/EditCustomField, NamePrefix => 'Default-', CustomField => $CustomFieldObj &>
+<& /Elements/EditCustomField, NamePrefix => 'Default-', CustomField => $CustomFieldObj, ShowEmptyOption => 1 &>
 </td>
 </tr>
 % }
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index e1c010b..cd9a4e6 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -104,10 +104,12 @@ jQuery(  function () {
 <fieldset class="cfedit">
 <div data-name="<%$name%>" id="<%$name%>">
 %   if ( $checktype eq 'radio' ) {
+% if ( $show_empty_option ) {
   <div class="none">
   <input class="none" type="<% $checktype %>" name="<% $name %>" id="<% $name %>-none" value="" <% keys %default ? '' : ' checked="checked"' |n%> />
   <label for="<% $name %>-none"><&|/l&>(no value)</&></label><br />
   </div>
+% }
 %   }
 %   my $CFVs = $CustomField->Values;
 %   while ( my $value = $CFVs->Next ) {
@@ -125,7 +127,9 @@ jQuery(  function () {
 %# this hidden select is to supply a full list of values,
 %# see filter_cascade_select() in js/cascaded.js
       <select name="<%$name%>-Complete" id="<%$name%>-Complete" class="hidden" disabled="disabled">
+% if ( $show_empty_option ) {
         <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
+% }
 %       $m->out($out);
       </select>
 % }
@@ -135,7 +139,9 @@ jQuery(  function () {
   size="<% $Rows %>"
 % }
 <% $Multiple && qq[multiple="multiple"] |n %> >
+% if ( $show_empty_option ) {
 <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
+% }
 % $m->out($out);
 </select>
 % }
@@ -159,6 +165,22 @@ if ( !@Default && $Values ) {
     @Default = map $_->Content, @{ $Values->ItemsArrayRef };
 }
 my %default = map {lc $_ => 1} @Default;
+
+my $show_empty_option;
+if ( exists $ARGS{ShowEmptyOption} ) {
+    $show_empty_option = $ARGS{ShowEmptyOption};
+}
+else {
+    if ( $CustomField->MatchPattern('') ) {
+        $show_empty_option = 1;
+    }
+    elsif ( $CustomField->SupportDefaultValues ) {
+        my ( $on ) = grep { $_->isa( $CustomField->RecordClassFromLookupType ) } $CustomField->ACLEquivalenceObjects;
+        my $default_values = $CustomField->DefaultValues( Object => $on || RT->System );
+        $show_empty_option = 1 unless defined $default_values && length $default_values;
+    }
+}
+
 </%init>
 <%ARGS>
 $Object => undef

-----------------------------------------------------------------------


More information about the rt-commit mailing list