Skip to content

Commit

Permalink
Support to skip label for EditCustomField
Browse files Browse the repository at this point in the history
We added label support in 701adc6. Sadly that there are still cases where
we only want the value part, like in RT::Extension::FormTools extension.
  • Loading branch information
sunnavy committed Feb 13, 2025
1 parent bb88aca commit 6884bce
Showing 1 changed file with 66 additions and 38 deletions.
104 changes: 66 additions & 38 deletions share/html/Elements/EditCustomField
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,17 @@
%#
%# END BPS TAGGED BLOCK }}}

% if ( $ShowLabel ) {
<&| /Elements/LabeledValue,
Label => ( $Label ? $Label : $CustomField->Name ),
LabelFor => $Name,
LabelTooltip => $CustomField->EntryHint,
FormText => $FormText &>

<%perl>
$m->comp(
$EditComponent,
%ARGS,
Rows => $Rows,
Cols => $Cols,
Default => $Default,
Object => $Object,
Values => $Values,
MaxValues => $MaxValues,
Multiple => ($MaxValues != 1),
NamePrefix => $NamePrefix,
CustomField => $CustomField,
Name => $Name,
$CustomField->BasedOn && $Name ? ( BasedOnName => GetCustomFieldInputName(Object => $Object, CustomField => $CustomField->BasedOnObj, Grouping => $Grouping) ) : (),
DescribedBy => $CFHintId,
AddClass => $AddClass,
);

if ( $error_msg ) {
</%perl>
<span id="<% $CFHintId %>" class="form-text invalid-feedback cfinvalidfield d-inline-block"><% $error_msg %></span>
% } elsif ($ShowHints and $CustomField->FriendlyPattern) {
<span id="<% $CFHintId %>" class="form-text cfhints d-inline-block">
<% $CustomField->FriendlyPattern %>
</span>
% }
% $m->callback( CallbackName => 'AfterCustomFieldValue', CustomField => $CustomField, Object => $Object, Grouping => $Grouping );
<& SELF:Content, %ARGS, EditComponent => $EditComponent, Values => $Values, MaxValues => $MaxValues, Name => $Name, CFHintId => $CFHintId, AddClass => $AddClass, ErrorMessage => $error_msg &>
</&>
% } else {
<& SELF:Content, %ARGS, EditComponent => $EditComponent, Values => $Values, MaxValues => $MaxValues, Name => $Name, CFHintId => $CFHintId, AddClass => $AddClass, ErrorMessage => $error_msg &>
% }

<%INIT>

Expand All @@ -91,6 +67,13 @@ unless ( $Type ) {
return;
}

my $FormText;
if ( $Type eq 'Date' || $Type eq 'DateTime' ) {
my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
$DateObj->Set( Format => 'unknown', Value => $Default, Timezone => 'utc' );
$FormText = $DateObj->AsString(Time => $Type eq 'Date' ? 0 : 1, Timezone => 'utc');
}

my $Values;
if ( $Object ) {
$Grouping =~ s/\W//g if $Grouping;
Expand Down Expand Up @@ -183,27 +166,72 @@ if ( $m->notes('InvalidField-' . $CustomField->Id . ($Grouping ? "-$Grouping" :
}

my $EditComponent = "EditCustomField$Type";
$m->callback( %ARGS, CallbackName => 'EditComponentName', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
$m->callback( %ARGS, CallbackName => 'EditComponentName', CallbackPage => '/Elements/EditCustomField', Name => \$EditComponent, CustomField => $CustomField, Object => $Object, Rows => \$Rows, Cols => \$Cols);
$EditComponent = "EditCustomField$Type" unless $m->comp_exists($EditComponent);

my $FormText;

if ( $Type eq 'Date' || $Type eq 'DateTime' ) {
my $DateObj = RT::Date->new ( $session{'CurrentUser'} );
$DateObj->Set( Format => 'unknown', Value => $Default, Timezone => 'utc' );
$FormText = $DateObj->AsString(Time => $Type eq 'Date' ? 0 : 1, Timezone => 'utc');
}

</%INIT>
<%ARGS>
$Grouping => undef
$Object => undef
$CustomField => undef
$Label => undef
$NamePrefix => undef
$Rows => 5
$Cols => undef
$Default => undef
$DefaultsFromTopArguments => 1
$ShowHints => undef
$ShowLabel => 1
</%ARGS>

<%METHOD Content>

<%ARGS>
$EditComponent => ''
$Values => ''
$MaxValues => ''
$Name => ''
$CFHintId => ''
$AddClass => ''
$ErrorMessage => '',

$Grouping => undef
$Object => undef
$CustomField => undef
$Label => undef
$NamePrefix => undef
$Rows => 5
$Cols => undef
$Default => undef
$DefaultsFromTopArguments => 1
$ShowHints => undef
</%ARGS>
<%perl>
$m->comp(
$EditComponent,
%ARGS,
Rows => $Rows,
Cols => $Cols,
Default => $Default,
Object => $Object,
Values => $Values,
MaxValues => $MaxValues,
Multiple => ($MaxValues != 1),
NamePrefix => $NamePrefix,
CustomField => $CustomField,
Name => $Name,
$CustomField->BasedOn && $Name ? ( BasedOnName => GetCustomFieldInputName(Object => $Object, CustomField => $CustomField->BasedOnObj, Grouping => $Grouping) ) : (),
DescribedBy => $CFHintId,
AddClass => $AddClass,
);

if ( $ErrorMessage ) {
</%perl>
<span id="<% $CFHintId %>" class="form-text invalid-feedback cfinvalidfield d-inline-block"><% $ErrorMessage %></span>
% } elsif ($ShowHints and $CustomField->FriendlyPattern) {
<span id="<% $CFHintId %>" class="form-text cfhints d-inline-block">
<% $CustomField->FriendlyPattern %>
</span>
% }
% $m->callback( CallbackName => 'AfterCustomFieldValue', CallbackPage => '/Elements/EditCustomField', CustomField => $CustomField, Object => $Object, Grouping => $Grouping );
</%METHOD>

0 comments on commit 6884bce

Please sign in to comment.