[Rt-commit] rt branch, 4.2/cf-input-name-sub, created. rt-4.2.1-154-g573fbee

? sunnavy sunnavy at bestpractical.com
Sat Jan 4 19:51:45 EST 2014


The branch, 4.2/cf-input-name-sub has been created
        at  573fbee7aeedf4edadbf82b9433418af951a5e65 (commit)

- Log -----------------------------------------------------------------
commit 573fbee7aeedf4edadbf82b9433418af951a5e65
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jan 3 00:47:48 2014 +0800

    refactor cf input name and abstract a sub to get it
    
    previously we have to do things like:
    
        my $input_name = "Object-RT::Ticket-" . $ticket->id . "-CustomField-" . $cf->id .  "-Value";
    
    this is complex enough to be wrapped into a sub, not mentioning that you need
    to figure out if it's "-Value" or "-Values". some notes:
    
    * the new sub mimics old naming convension for back compatibility.
    * old $NamePrefix is still supported(if the new added arg $Name is not set)
    * ...-Values-Magic is widened to ...-Magic(so there will be ...-Value-Magic,
      ...-Upload-Magic, etc because now we simply suffix "-Magic" to the input name)
    
    this commit respects current inconsistent "-Value" vs "-Values" usage, but we
    should fix it in the near futuer:
    
    * cfs with single-value should be named as single "-Value" instead of "-Values"
      e.g. Date, DateTime, single Select with render type "List" and maybe also
      Text and WikiText
    * upload cfs(Binary and Image) should be named as "-Uploads" if they are not single-valued.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 7082a28..8c811a7 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1716,6 +1716,50 @@ sub RewriteInlineImages {
     return @rewritten;
 }
 
+=head2 GetCustomFieldInputName(CustomField => $cf_object, Object => $object, Grouping => $grouping_name)
+
+Returns the standard custom field input name, which is complement to _ParseObjectCustomFieldArgs
+
+=cut
+
+sub GetCustomFieldInputName {
+    my %args = (
+        CustomField => undef,
+        Object      => undef,
+        Grouping    => undef,
+        @_,
+    );
+
+    my $name = join '-', 'Object', ref( $args{Object} ) || $args{CustomField}->ObjectTypeFromLookupType,
+        ( $args{Object} && $args{Object}->id ? $args{Object}->id : '' ),
+        'CustomField' . ( $args{Grouping} ? ":$args{Grouping}" : '' ), $args{CustomField}->id;
+
+    if ( $args{CustomField}->Type eq 'Select' ) {
+        if ( $args{CustomField}->RenderType eq 'List' ) {
+            $name .= '-Value';
+        }
+        else {
+            $name .= '-Values';
+        }
+    }
+    elsif ( $args{CustomField}->Type =~ /^(?:Binary|Image)$/ ) {
+        $name .= '-Upload';
+    }
+    elsif ( $args{CustomField}->Type =~ /^(?:Date|DateTime|Text|Wikitext)$/ ) {
+        $name .= '-Values';
+    }
+    else {
+        if ( $args{CustomField}->SingleValue ) {
+            $name .= '-Value';
+        }
+        else {
+            $name .= '-Values';
+        }
+    }
+
+    return $name;
+}
+
 package HTML::Mason::Commands;
 
 use vars qw/$r $m %session/;
@@ -2991,6 +3035,7 @@ sub _ParseObjectCustomFieldArgs {
     foreach my $arg ( keys %$ARGSRef ) {
 
         # format: Object-<object class>-<object id>-CustomField[:<grouping>]-<CF id>-<commands>
+        # you can use GetCustomFieldInputName to generate the complement input name
         next unless $arg =~ /^Object-([\w:]+)-(\d*)-CustomField(?::(\w+))?-(\d+)-(.*)$/;
 
         # For each of those objects, find out what custom fields we want to work with.
@@ -3010,7 +3055,7 @@ sub _ProcessObjectCustomFieldUpdates {
     # the browser gives you a blank value which causes CFs to be processed twice
     if (   defined $args{'ARGS'}->{'Values'}
         && !length $args{'ARGS'}->{'Values'}
-        && $args{'ARGS'}->{'Values-Magic'} )
+        && ($args{'ARGS'}->{'Values-Magic'} || $args{'ARGS'}->{'Value-Magic'}) || $args{'ARGS'}->{'Upload-Magic'})
     {
         delete $args{'ARGS'}->{'Values'};
     }
@@ -3023,7 +3068,7 @@ sub _ProcessObjectCustomFieldUpdates {
 
         # since http won't pass in a form element with a null value, we need
         # to fake it
-        if ( $arg eq 'Values-Magic' ) {
+        if ( $arg =~ /-Magic$/ ) {
 
             # We don't care about the magic, if there's really a values element;
             next if defined $args{'ARGS'}->{'Value'}  && length $args{'ARGS'}->{'Value'};
@@ -3166,7 +3211,7 @@ sub ProcessObjectCustomFieldUpdatesForCreate {
             while (my ($arg, $value) = each %{ $custom_fields{$class}{0}{$cfid}{$groupings[0]} }) {
                 # Values-Magic doesn't matter on create; no previous values are being removed
                 # Category is irrelevant for the actual value
-                next if $arg eq "Values-Magic" or $arg eq "Category";
+                next if $arg =~ /-Magic$/ or $arg eq "Category";
 
                 push @values, _NormalizeObjectCustomFieldValue(
                     CustomField => $cf,
@@ -3903,6 +3948,10 @@ sub CSSClass {
     return $value;
 }
 
+sub GetCustomFieldInputName {
+    RT::Interface::Web::GetCustomFieldInputName(@_);
+}
+
 package RT::Interface::Web;
 RT::Base->_ImportOverlays();
 
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField
index 1965557..5328b1a 100644
--- a/share/html/Elements/EditCustomField
+++ b/share/html/Elements/EditCustomField
@@ -57,10 +57,6 @@ unless ( $Type ) {
 my $Values;
 if ( $Object ) {
     $Grouping =~ s/\W//g if $Grouping;
-    $NamePrefix ||= join '-',
-        'Object', ref($Object), ($Object->Id || ''),
-        'CustomField' . ($Grouping ? ":$Grouping" : ""),
-        '';
 
     if ( $Object->Id ) {
         $Values = $Object->CustomFieldValues( $CustomField->id );
@@ -74,10 +70,15 @@ if ( $Object ) {
     }
 }
 
+my $Name;
+if ( !$NamePrefix ) {
+    $Name = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
+}
+
 # Always fill $Default with submited values if it's empty
 if ( ( !defined $Default || !length $Default ) && $DefaultsFromTopArguments ) {
     my %TOP = %$DECODED_ARGS;
-    $Default = $TOP{ $NamePrefix .$CustomField->Id . '-Values' }
+    $Default = $Name ? $TOP{ $Name } : $TOP{ $NamePrefix .$CustomField->Id . '-Values' }
             || $TOP{ $NamePrefix .$CustomField->Id . '-Value' };
 }
 
@@ -90,7 +91,10 @@ if ($MaxValues == 1 && $Values) {
 }
 # The "Magic" hidden input causes RT to know that we were trying to edit the field, even if 
 # we don't see a value later, since browsers aren't compelled to submit empty form fields
-$m->out("\n".'<input type="hidden" class="hidden" name="'.$m->interp->apply_escapes($NamePrefix, 'h').$CustomField->Id.'-Values-Magic" value="1" />'."\n");
+$m->out("\n".'<input type="hidden" class="hidden" name="'
+        . ($Name ? $m->interp->apply_escapes($Name, 'h') : $m->interp->apply_escapes($NamePrefix, 'h').$CustomField->Id.'-Values')
+        . '-Magic" value="1" />'."\n");
+
 
 my $EditComponent = "EditCustomField$Type";
 $m->callback( %ARGS, CallbackName => 'EditComponentName', Name => \$EditComponent, CustomField => $CustomField, Object => $Object );
@@ -108,6 +112,8 @@ return $m->comp(
     Multiple => ($MaxValues != 1),
     NamePrefix => $NamePrefix,
     CustomField => $CustomField,
+    Name => $Name,
+    $CustomField->BasedOn && $Name ? ( BasedOnName => GetCustomFieldInputName(Object => $Object, CustomField => $CustomField->BasedOnObj, Grouping => $Grouping) ) : (),
 );
 </%INIT>
 <%ARGS>
diff --git a/share/html/Elements/EditCustomFieldAutocomplete b/share/html/Elements/EditCustomFieldAutocomplete
index 4a0c5cf..6b6272f 100644
--- a/share/html/Elements/EditCustomFieldAutocomplete
+++ b/share/html/Elements/EditCustomFieldAutocomplete
@@ -46,13 +46,13 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 % if ( $Multiple ) {
-<textarea cols="<% $Cols %>" rows="<% $Rows %>" name="<% $name %>-Values" id="<% $name %>-Values" class="CF-<%$CustomField->id%>-Edit"><% $Default || '' %></textarea>
+<textarea cols="<% $Cols %>" rows="<% $Rows %>" name="<% $name %>" id="<% $name %>" class="CF-<%$CustomField->id%>-Edit"><% $Default || '' %></textarea>
 
 <script type="text/javascript">
-var id = <% "$name-Values" |n,j%>;
+var id = <% "$name" |n,j%>;
 id = id.replace(/:/g,'\\:');
 jQuery('#'+id).autocomplete( {
-    source: RT.Config.WebHomePath + "/Helpers/Autocomplete/CustomFieldValues?"+<% $Context |n,j %>+<% "$name-Values" |n,u,j%>,
+    source: RT.Config.WebHomePath + "/Helpers/Autocomplete/CustomFieldValues?"+<% $Context |n,j %>+<% $name |n,u,j%>,
     focus: function () {
         // prevent value inserted on focus
         return false;
@@ -71,18 +71,18 @@ jQuery('#'+id).autocomplete( {
 }
 );
 % } else {
-<input type="text" id="<% $name %>-Value" name="<% $name %>-Value" class="CF-<%$CustomField->id%>-Edit" value="<% $Default || '' %>"/>
+<input type="text" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit" value="<% $Default || '' %>"/>
 <script type="text/javascript">
-var id = <% "$name-Value" |n,j%>;
+var id = <% $name |n,j%>;
 id = id.replace(/:/g,'\\:');
 jQuery('#'+id).autocomplete( {
-    source: RT.Config.WebHomePath + "/Helpers/Autocomplete/CustomFieldValues?"+<% $Context |n,j %>+<% "$name-Value" |n,u,j%>
+    source: RT.Config.WebHomePath + "/Helpers/Autocomplete/CustomFieldValues?"+<% $Context |n,j %>+<% $name |n,u,j%>
 }
 );
 % }
 </script>
 <%INIT>
-my $name = $NamePrefix . $CustomField->Id;
+my $name = $Name || $NamePrefix . $CustomField->Id . ( $Multiple ?  '-Values' : '-Value' );
 if ( $Default && !$Multiple ) {
     $Default =~ s/\s*\r*\n\s*/ /g;
 }
@@ -101,6 +101,7 @@ if ($CustomField->ContextObject) {
 <%ARGS>
 $CustomField => undef
 $NamePrefix  => undef
+$Name        => undef
 $Default     => undef
 $Values      => undef
 $Multiple    => undef
diff --git a/share/html/Elements/EditCustomFieldBinary b/share/html/Elements/EditCustomFieldBinary
index 475f4a4..22bb150 100644
--- a/share/html/Elements/EditCustomFieldBinary
+++ b/share/html/Elements/EditCustomFieldBinary
@@ -47,18 +47,26 @@
 %# END BPS TAGGED BLOCK }}}
 % while ( $Values and my $value = $Values->Next ) {
 %# XXX - let user download the file(s) here?
-<input type="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" class="checkbox CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" /><a href="<%RT->Config->Get('WebPath')%>/Download/CustomFieldValue/<% $value->Id %>/<% $value->Content |un %>"><% $value->Content %></a><br />
+<input type="checkbox" name="<%$delete_name%>" class="checkbox CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" /><a href="<%RT->Config->Get('WebPath')%>/Download/CustomFieldValue/<% $value->Id %>/<% $value->Content |un %>"><% $value->Content %></a><br />
 % }
 % if ($MaxValues && $Values && $Values->Count >= $MaxValues ) {
 <div class="hints">
 <&|/l&>Reached maximum number, so new values will override old ones.</&>
 </div>
 % }
-<input type="file" name="<% $NamePrefix %><% $CustomField->Id %>-Upload" class="CF-<%$CustomField->id%>-Edit" />
+<input type="file" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit" />
+
+<%INIT>
+my $name = $Name || $NamePrefix . $CustomField->Id . '-Upload';
+my $delete_name = $name;
+$delete_name =~ s!-Upload$!-DeleteValueIds!;
+</%INIT>
+
 <%ARGS>
 $Object => undef
 $CustomField => undef
 $NamePrefix => undef
+$Name   => undef
 $Default => undef
 $Values => undef
 $MaxValues => undef
diff --git a/share/html/Elements/EditCustomFieldCombobox b/share/html/Elements/EditCustomFieldCombobox
index a3e304e..110fa85 100644
--- a/share/html/Elements/EditCustomFieldCombobox
+++ b/share/html/Elements/EditCustomFieldCombobox
@@ -46,18 +46,25 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 % while ($Values and my $value = $Values->Next and $Multiple) {
-<input type="checkbox" id="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" class="checkbox CF-<%$CustomField->id%>-Edit" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" class="CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" />
-<label for="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds"><% $value->Content %></label>
+<input type="checkbox" id="<%$delete_name%>" class="checkbox CF-<%$CustomField->id%>-Edit" name="<%$delete_name%>" class="CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" />
+<label for="<%$delete_name%>"><% $value->Content %></label>
 <br />
 % }
 % (!$Multiple or !$MaxValues or !$Values or $Values->Count < $MaxValues) or return;
 <& /Widgets/ComboBox,
-    Name    => $NamePrefix . $CustomField->Id . "-Value",
+    Name    => $Name,
     Default => $Default,
     Rows    => $Rows,
     Class   => "CF-".$CustomField->id."-Edit",
     Values  => [map {$_->Name} @{$CustomField->Values->ItemsArrayRef}],
 &>
+
+<%INIT>
+my $name = $Name || $NamePrefix . $CustomField->Id . '-Value';
+my $delete_name = $name;
+$delete_name =~ s!-Value$!-DeleteValueIds!;
+</%INIT>
+
 <%ARGS>
 $Object => undef
 $CustomField => undef
@@ -67,4 +74,5 @@ $Values => undef
 $Multiple => 0
 $Rows => undef
 $MaxValues => undef
+$Name => undef
 </%ARGS>
diff --git a/share/html/Elements/EditCustomFieldDate b/share/html/Elements/EditCustomFieldDate
index 9e190be..c349849 100644
--- a/share/html/Elements/EditCustomFieldDate
+++ b/share/html/Elements/EditCustomFieldDate
@@ -45,7 +45,7 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-% my $name = $NamePrefix.$CustomField->Id.'-Values';
+% my $name = $Name || $NamePrefix.$CustomField->Id.'-Values';
 <& /Elements/SelectDate, Name => "$name", current => 0, ShowTime => 0 &> (<%$DateObj->AsString(Time => 0, Timezone => 'utc')%>)
 
 <%INIT>
@@ -59,4 +59,5 @@ $NamePrefix => undef
 $Default => undef
 $Values => undef
 $MaxValues => 1
+$Name => undef
 </%ARGS>
diff --git a/share/html/Elements/EditCustomFieldDateTime b/share/html/Elements/EditCustomFieldDateTime
index 3d94855..53ab15b 100644
--- a/share/html/Elements/EditCustomFieldDateTime
+++ b/share/html/Elements/EditCustomFieldDateTime
@@ -45,7 +45,7 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-% my $name = $NamePrefix.$CustomField->Id.'-Values';
+% my $name = $Name || $NamePrefix.$CustomField->Id.'-Values';
 <& /Elements/SelectDate, Name => "$name", current => 0 &> (<%$DateObj->AsString%>)
 
 <%INIT>
@@ -59,4 +59,5 @@ $NamePrefix => undef
 $Default => undef
 $Values => undef
 $MaxValues => 1
+$Name => undef
 </%ARGS>
diff --git a/share/html/Elements/EditCustomFieldFreeform b/share/html/Elements/EditCustomFieldFreeform
index b6810b6..80a52f4 100644
--- a/share/html/Elements/EditCustomFieldFreeform
+++ b/share/html/Elements/EditCustomFieldFreeform
@@ -45,9 +45,9 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-% my $name = $NamePrefix . $CustomField->Id . '-Value';
+% my $name = $Name || $NamePrefix . $CustomField->Id . ( $Multiple ? '-Values' : '-Value' );
 % if ($Multiple) {
-<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>s" id="<%$name%>s" wrap="off" class="CF-<%$CustomField->id%>-Edit"><% defined($Default) ? $Default : '' %></textarea>
+<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>" id="<%$name%>" wrap="off" class="CF-<%$CustomField->id%>-Edit"><% defined($Default) ? $Default : '' %></textarea>
 % } else {
 <input name="<%$name%>" id="<%$name%>" size="<%$Cols%>" class="CF-<%$CustomField->id%>-Edit" value="<% defined($Default) ? $Default : ''%>" />
 % }
@@ -63,6 +63,7 @@ unless ( $Multiple ) {
 $Object => undef
 $CustomField => undef
 $NamePrefix => undef
+$Name => undef
 $Default => undef
 $Values => undef
 $Multiple => undef
diff --git a/share/html/Elements/EditCustomFieldImage b/share/html/Elements/EditCustomFieldImage
index b28a72b..13c48c6 100644
--- a/share/html/Elements/EditCustomFieldImage
+++ b/share/html/Elements/EditCustomFieldImage
@@ -46,7 +46,7 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 % while ($Values and my $value = $Values->Next ) {
-<input type="checkbox" class="checkbox" name="<%$NamePrefix%><%$CustomField->Id%>-DeleteValueIds" class="CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" /><& ShowCustomFieldImage, Object => $value &>
+<input type="checkbox" class="checkbox" name="<%$delete_name%>" class="CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>" /><& ShowCustomFieldImage, Object => $value &>
 <br />
 % }
 % if ($MaxValues && $Values && $Values->Count >= $MaxValues ) {
@@ -54,11 +54,19 @@
 <&|/l&>Reached maximum number, so new values will override old ones.</&>
 </div>
 % }
-<input type="file" name="<%$NamePrefix%><%$CustomField->Id%>-Upload" class="CF-<%$CustomField->id%>-Edit" />
+<input type="file" name="<%$name%>" class="CF-<%$CustomField->id%>-Edit" />
+
+<%INIT>
+my $name = $Name || $NamePrefix . $CustomField->Id . '-Upload';
+my $delete_name = $name;
+$delete_name =~ s!-Upload$!-DeleteValueIds!;
+</%INIT>
+
 <%ARGS>
 $Object => undef
 $CustomField => undef
 $NamePrefix => undef
+$Name => undef
 $Default => undef
 $Values => undef
 $MaxValues => undef
diff --git a/share/html/Elements/EditCustomFieldSelect b/share/html/Elements/EditCustomFieldSelect
index 234b532..944608e 100644
--- a/share/html/Elements/EditCustomFieldSelect
+++ b/share/html/Elements/EditCustomFieldSelect
@@ -50,11 +50,10 @@
 %# (perhaps by tweaking the .display style?)
 % my $selected = 0;
 % my @category;
-% my $id = $NamePrefix . $CustomField->Id;
 % my $out = $m->scomp('SELF:options', %ARGS, SelectedRef => \$selected, CategoryRef => \@category);
 % if (!$HideCategory and @category and not $CustomField->BasedOnObj->id) {
 %# XXX - Hide this select from w3m?
-  <select onchange="filter_cascade_by_id(<% "$id-Values" |n,j%>, this.value)" name="<% $id %>-Category" class="CF-<%$CustomField->id%>-Edit">
+  <select onchange="filter_cascade_by_id(<% $name |n,j %>, this.value)" name="<% $name %>-Category" class="CF-<%$CustomField->id%>-Edit">
     <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>-</&></option>
 %   foreach my $cat (@category) {
 %     my ($depth, $name) = @$cat;
@@ -62,9 +61,10 @@
 %   }
     </select><br />
 % } elsif ($CustomField->BasedOnObj->id) {
+
 <script type="text/javascript"><!--
 jQuery(  function () {
-    var basedon = jQuery('[name^="<% $NamePrefix .  $CustomField->BasedOnObj->id %>-Value"][type!="hidden"]:input:not(.hidden)');
+    var basedon = jQuery('[name^="<% $BasedOnName || $NamePrefix . $CustomField->BasedOnObj->id . '-Value' |n %>"][type!="hidden"]:input:not(.hidden)');
     basedon.each( function() {
         var oldchange = jQuery(this).onchange;
         jQuery(this).change( function () {
@@ -81,7 +81,7 @@ jQuery(  function () {
                 });
             }
             filter_cascade_by_id(
-                <% "$id-Values" |n,j%>,
+                <% $name |n,j%>,
                 vals,
                 true
             );
@@ -102,7 +102,7 @@ jQuery(  function () {
 
 % if ( $RenderType eq 'List' ) {
 <fieldset class="cfedit">
-<div name="<%$id%>-Values" id="<%$id%>-Values">
+<div name="<%$name%>" id="<%$name%>">
 %   if ( $checktype eq 'radio' ) {
   <div class="none">
   <input class="none" type="<% $checktype %>" name="<% $name %>" id="<% $name %>-none" value="" <% keys %default ? '' : ' checked="checked"' |n%> />
@@ -124,13 +124,13 @@ jQuery(  function () {
 % if (@category) {
 %# this hidden select is to supply a full list of values,
 %# see filter_cascade_select() in js/cascaded.js
-      <select name="<%$id%>-Values-Complete" id="<%$id%>-Values-Complete" class="hidden" disabled="disabled">
+      <select name="<%$name%>-Complete" id="<%$name%>-Complete" class="hidden" disabled="disabled">
         <option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
 %       $m->out($out);
       </select>
 % }
 <select
-  name="<%$id%>-Values" id="<%$id%>-Values" class="CF-<%$CustomField->id%>-Edit"
+  name="<%$name%>" id="<%$name%>" class="CF-<%$CustomField->id%>-Edit"
 % if ( $Rows && ( $Multiple || !@category || $RenderType eq 'Select box') ) {
   size="<% $Rows %>"
 % }
@@ -149,10 +149,11 @@ if ( $RenderType eq 'Dropdown' ) {
 
 # The following is for rendering checkboxes / radio buttons only
 my ($checktype, $name);
+
 if ( $MaxValues == 1 ) {
-    ($checktype, $name) = ('radio', $NamePrefix . $CustomField->Id . '-Value');
+    ($checktype, $name) = ('radio', $Name || $NamePrefix . $CustomField->Id . '-Value');
 } else {
-    ($checktype, $name) = ('checkbox', $NamePrefix . $CustomField->Id . '-Values');
+    ($checktype, $name) = ('checkbox', $Name || $NamePrefix . $CustomField->Id . '-Values');
 }
 
 @Default = grep defined && length, @Default;
@@ -165,6 +166,8 @@ my %default = map {lc $_ => 1} @Default;
 $Object => undef
 $CustomField => undef
 $NamePrefix => undef
+$Name => undef
+$BasedOnName => undef
 @Default => ()
 $Values => undef
 $Multiple => 0
diff --git a/share/html/Elements/EditCustomFieldText b/share/html/Elements/EditCustomFieldText
index c169740..467fab7 100644
--- a/share/html/Elements/EditCustomFieldText
+++ b/share/html/Elements/EditCustomFieldText
@@ -46,19 +46,21 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 % while ($Values and my $value = $Values->Next ) {
-<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$NamePrefix%><%$CustomField->Id%>-Values" class="CF-<%$CustomField->id%>-Edit"><% $value->Content %></textarea><br />
+<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>" class="CF-<%$CustomField->id%>-Edit"><% $value->Content %></textarea><br />
 % }
 % if (!$MaxValues or !$Values or $Values->Count < $MaxValues) {
-<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$NamePrefix%><%$CustomField->Id%>-Values" class="CF-<%$CustomField->id%>-Edit"><% defined($Default) ? $Default : '' %></textarea>
+<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>" class="CF-<%$CustomField->id%>-Edit"><% defined($Default) ? $Default : '' %></textarea>
 % }
 <%INIT>
 # XXX - MultiValue textarea is for now outlawed.
 $MaxValues = 1;
+my $name = $Name || $NamePrefix . $CustomField->Id . '-Values';
 </%INIT>
 <%ARGS>
 $Object => undef
 $CustomField => undef
 $NamePrefix => ''
+$Name => undef
 $Default => undef
 $Values => undef
 $MaxValues => undef
diff --git a/share/html/Elements/EditCustomFieldWikitext b/share/html/Elements/EditCustomFieldWikitext
index ac2de26..a469171 100644
--- a/share/html/Elements/EditCustomFieldWikitext
+++ b/share/html/Elements/EditCustomFieldWikitext
@@ -46,19 +46,21 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 % while ($Values and my $value = $Values->Next ) {
-<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$NamePrefix%><%$CustomField->Id%>-Values" class="CF-<%$CustomField->id%>-Edit"><% $value->Content %></textarea><br />
+<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>" class="CF-<%$CustomField->id%>-Edit"><% $value->Content %></textarea><br />
 % }
 % if (!$MaxValues or !$Values or $Values->Count < $MaxValues) {
-<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$NamePrefix%><%$CustomField->Id%>-Values" class="CF-<%$CustomField->id%>-Edit"><% $Default %></textarea>
+<textarea cols="<%$Cols%>" rows="<%$Rows%>" name="<%$name%>" class="CF-<%$CustomField->id%>-Edit"><% $Default %></textarea>
 % }
 <%INIT>
 # XXX - MultiValue textarea is for now outlawed.
 $MaxValues = 1;
+my $name = $Name || $NamePrefix . $CustomField->Id . '-Values';
 </%INIT>
 <%ARGS>
 $Object => undef
 $CustomField => undef
 $NamePrefix => undef
+$Name => undef
 $Default => undef
 $Values => undef
 $MaxValues => undef
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 75e6709..6e7e944 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -352,10 +352,10 @@ if ($CloneTicket) {
         }
 
         if ( @cf_values > 1 && $cf->Type eq 'Select' ) {
-            $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = \@cf_values;
+            $clone->{GetCustomFieldInputName( CustomField => $cf )} = \@cf_values;
         }
         else {
-            $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
+            $clone->{GetCustomFieldInputName( CustomField => $cf )} = join "\n",
               @cf_values;
         }
     }
diff --git a/share/html/m/ticket/create b/share/html/m/ticket/create
index a8d7a89..2e53cb1 100644
--- a/share/html/m/ticket/create
+++ b/share/html/m/ticket/create
@@ -125,7 +125,7 @@ if ($CloneTicket) {
         while ( my $cf_value = $cf_values->Next ) {
             push @cf_values, $cf_value->Content;
         }
-        $clone->{"Object-RT::Ticket--CustomField-$cf_id-Value"} = join "\n",
+        $clone->{GetCustomFieldInputName( CustomField => $cf )} = join "\n",
             @cf_values;
     }
 
diff --git a/t/web/cf_pattern.t b/t/web/cf_pattern.t
index b99df03..ff85ec6 100644
--- a/t/web/cf_pattern.t
+++ b/t/web/cf_pattern.t
@@ -29,12 +29,14 @@ for my $page ("/Ticket/Create.html?Queue=1", "/Ticket/Modify.html?id=".$ticket->
     $m->content_contains("Input must match [Digits]");
     $m->content_lacks("cfinvalidfield");
 
-    my $cfinput = join "-", "Object", "RT::Ticket", ($page =~ /Create/ ? "" : $ticket->id),
-                            "CustomField", $cf->id, "Value";
+    my $cfinput = RT::Interface::Web::GetCustomFieldInputName(
+        Object => ( $page =~ /Create/ ? RT::Ticket->new( RT->SystemUser ) : $ticket ),
+        CustomField => $cf,
+    );
     $m->submit_form_ok({
         with_fields => {
             $cfinput            => "too many",
-            "${cfinput}s-Magic" => "1",
+            "${cfinput}-Magic" => "1",
         },
     });
     $m->content_contains("Input must match [Digits]");
@@ -43,7 +45,7 @@ for my $page ("/Ticket/Create.html?Queue=1", "/Ticket/Modify.html?id=".$ticket->
     $m->submit_form_ok({
         with_fields => {
             $cfinput            => "42",
-            "${cfinput}s-Magic" => "1",
+            "${cfinput}-Magic" => "1",
         },
     });
 

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


More information about the rt-commit mailing list