Skip to content

Commit

Permalink
Add required attribute for mandatory custom field inputs
Browse files Browse the repository at this point in the history
The attribute isn't enabled for radio/checkbox inputs. "(no value)"
passes the "required" limitation for radio, which makes it useless. For
checkbox, "required" indicates all "required" checkbox inputs(even with
the same name) must be checked, which is not what want either.
  • Loading branch information
sunnavy committed Nov 3, 2023
1 parent 464dacd commit e27523f
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 7 deletions.
2 changes: 1 addition & 1 deletion share/html/Admin/CustomFields/Modify.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
% if ( $CustomFieldObj->SupportDefaultValues ) {
<&| /Elements/LabeledValue, Label => loc("Default [numerate,_1,value,values]", $CustomFieldObj->MaxValues),
Class => $default_value_class &>
<& /Elements/EditCustomField, NamePrefix => 'Default-', CustomField => $CustomFieldObj, ShowEmptyOption => 1 &>
<& /Elements/EditCustomField, NamePrefix => 'Default-', CustomField => $CustomFieldObj, ShowEmptyOption => 1, Required => 0 &>
</&>
% }

Expand Down
5 changes: 5 additions & 0 deletions share/html/Admin/Queues/DefaultValues.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
Grouping => 'Basics',
CategoryObj => $queue,
Required => 0,
&>

<&| /Elements/LabeledValue, Label => loc('Article') &>
Expand All @@ -91,6 +92,7 @@
CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
Grouping => 'Dates',
CategoryObj => $queue,
Required => 0,
&>
</&>
</div>
Expand All @@ -103,6 +105,7 @@
CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
Grouping => 'People',
CategoryObj => $queue,
Required => 0,
&>
</&>
</div>
Expand All @@ -116,6 +119,7 @@
CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
Grouping => 'Links',
CategoryObj => $queue,
Required => 0,
&>
</&>
</div>
Expand All @@ -126,6 +130,7 @@
Object => RT::Ticket->new($session{CurrentUser}),
Groupings => \@groupings,
CategoryObj => $queue,
Required => 0,
&>

<div class="ticket-info-cfs">
Expand Down
1 change: 1 addition & 0 deletions share/html/Elements/EditCustomField
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,5 @@ $Rows => 5
$Cols => 15
$Default => undef
$DefaultsFromTopArguments => 1,
$Required => undef
</%ARGS>
10 changes: 9 additions & 1 deletion share/html/Elements/EditCustomFieldAutocomplete
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
% if ( $Required ) {
required
% }
name="<% $name %>" id="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control"><% $Default || '' %></textarea>

<script type="text/javascript">
Expand All @@ -78,7 +81,11 @@ jQuery('#'+id).autocomplete( {
}
);
% } else {
<input type="text" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control" value="<% $Default || '' %>"/>
<input type="text" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit form-control" value="<% $Default || '' %>"
% if ( $Required ) {
required
% }
/>
<script type="text/javascript">
var id = <% $name |n,j%>;
id = id.replace(/:/g,'\\:');
Expand Down Expand Up @@ -114,4 +121,5 @@ $Values => undef
$Multiple => undef
$Rows => undef
$Cols => undef
$Required => $CustomField->MatchPattern('') ? 0 : 1
</%ARGS>
7 changes: 6 additions & 1 deletion share/html/Elements/EditCustomFieldBinary
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
% }

<div class="custom-file">
<input type="file" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit custom-file-input" />
<input type="file" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit custom-file-input"
% if ( $Required ) {
required
% }
/>
<label class="custom-file-label" for="<% $name %>"><&|/l&>Choose file</&></label>
</div>

Expand All @@ -86,4 +90,5 @@ $Name => undef
$Default => undef
$Values => undef
$MaxValues => undef
$Required => ( ( $Values && $Values->Count ) || $CustomField->MatchPattern('') ) ? 0 : 1
</%ARGS>
2 changes: 2 additions & 0 deletions share/html/Elements/EditCustomFieldCombobox
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
Rows => $Rows,
Class => "CF-".$CustomField->id."-Edit",
Values => [map {$_->Name} @{CachedCustomFieldValues($CustomField)->ItemsArrayRef}],
Required => $Required,
&>

<%INIT>
Expand All @@ -76,4 +77,5 @@ $Multiple => 0
$Rows => undef
$MaxValues => undef
$Name => undef
$Required => $CustomField->MatchPattern('') ? 0 : 1
</%ARGS>
3 changes: 2 additions & 1 deletion share/html/Elements/EditCustomFieldDate
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
% my $name = $Name || $NamePrefix.$CustomField->Id.'-Values';
<div class="form-row">
<div class="col-auto">
<& /Elements/SelectDate, Name => $name, Default => $Default, current => 0, ShowTime => 0 &>
<& /Elements/SelectDate, Name => $name, Default => $Default, current => 0, ShowTime => 0, Required => $Required, &>
</div>
<div class="col-auto">
<span class="current-value form-control">(<%$DateObj->AsString(Time => 0, Timezone => 'utc')%>)</span>
Expand All @@ -66,4 +66,5 @@ $Default => undef
$Values => undef
$MaxValues => 1
$Name => undef
$Required => $CustomField->MatchPattern('') ? 0 : 1
</%ARGS>
3 changes: 2 additions & 1 deletion share/html/Elements/EditCustomFieldDateTime
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
% my $name = $Name || $NamePrefix.$CustomField->Id.'-Values';
<div class="form-row">
<div class="col-auto">
<& /Elements/SelectDate, Name => $name, Default => $Default, current => 0 &>
<& /Elements/SelectDate, Name => $name, Default => $Default, current => 0, Required => $Required, &>
</div>
<div class="col-auto">
<span class="current-value form-control">(<%$DateObj->AsString%>)</span>
Expand All @@ -68,4 +68,5 @@ $Values => undef
$MaxValues => 1
$Name => undef
$Format => 'unknown'
$Required => $CustomField->MatchPattern('') ? 0 : 1
</%ARGS>
7 changes: 7 additions & 0 deletions share/html/Elements/EditCustomFieldFreeform
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
% if ( $Required ) {
required
% }
name="<%$name%>" id="<%$name%>" wrap="off" class="CF-<%$CustomField->id%>-Edit form-control"><% defined($Default) ? $Default : '' %></textarea>
% } else {
<input type="text" name="<%$name%>" id="<%$name%>" \
% if ( defined $Cols ) {
size="<% $Cols %>" \
% }
% if ( $Required ) {
required
% }
class="CF-<%$CustomField->id%>-Edit form-control" value="<% defined($Default) ? $Default : ''%>" />
% }
<%INIT>
Expand All @@ -80,4 +86,5 @@ $Values => undef
$Multiple => undef
$Cols
$Rows
$Required => $CustomField->MatchPattern('') ? 0 : 1
</%ARGS>
4 changes: 4 additions & 0 deletions share/html/Elements/EditCustomFieldHTML
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
% if ( $Required ) {
required
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control richtext"><% $Default %></textarea>
% }
<%INIT>
Expand All @@ -81,4 +84,5 @@ $Values => undef
$MaxValues => undef
$Cols
$Rows
$Required => $CustomField->MatchPattern('') ? 0 : 1
</%ARGS>
7 changes: 6 additions & 1 deletion share/html/Elements/EditCustomFieldImage
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
% }

<div class="custom-file">
<input type="file" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit custom-file-input" />
<input type="file" id="<% $name %>" name="<% $name %>" class="CF-<%$CustomField->id%>-Edit custom-file-input"
% if ( $Required ) {
required
% }
/>
<label class="custom-file-label" for="<% $name %>"><&|/l&>Choose file</&></label>
</div>

Expand All @@ -78,4 +82,5 @@ $Name => undef
$Default => undef
$Values => undef
$MaxValues => undef
$Required => ( ( $Values && $Values->Count ) || $CustomField->MatchPattern('') ) ? 0 : 1
</%ARGS>
4 changes: 4 additions & 0 deletions share/html/Elements/EditCustomFieldSelect
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
% if ( $size > 1 ) {
size="<% $Rows %>"
% }
% if ( $Required ) {
required
% }
<% $Multiple && qq[multiple="multiple"] |n %> >
% if ( $show_empty_option ) {
<option value=""<% !$selected && qq[ selected="selected"] |n %>><&|/l&>(no value)</&></option>
Expand Down Expand Up @@ -191,6 +194,7 @@ $Rows => undef
$HideCategory => 0
$RenderType => undef
$MaxValues => 1
$Required => $CustomField->MatchPattern('') ? 0 : 1,
</%ARGS>

<%METHOD options>
Expand Down
4 changes: 4 additions & 0 deletions share/html/Elements/EditCustomFieldText
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
% if ( $Required ) {
required
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control"><% defined($Default) ? $Default : '' %></textarea>
% }
<%INIT>
Expand All @@ -80,4 +83,5 @@ $Values => undef
$MaxValues => undef
$Cols
$Rows
$Required => $CustomField->MatchPattern('') ? 0 : 1
</%ARGS>
4 changes: 4 additions & 0 deletions share/html/Elements/EditCustomFieldWikitext
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ cols="<% $Cols %>" \
% if ( defined $Rows ) {
rows="<% $Rows %>" \
% }
% if ( $Required ) {
required
% }
name="<%$name%>" class="CF-<%$CustomField->id%>-Edit form-control"><% $Default %></textarea>
% }
<%INIT>
Expand All @@ -80,4 +83,5 @@ $Values => undef
$MaxValues => undef
$Cols
$Rows
$Required => $CustomField->MatchPattern('') ? 0 : 1
</%ARGS>
1 change: 1 addition & 0 deletions share/html/Elements/EditCustomFields
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@ $LabelCols => 3
$ValueCols => 9
$ShowHints => 1
$ForCreation => 0
$Required => undef
</%ARGS>
4 changes: 4 additions & 0 deletions share/html/Elements/SelectDate
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<input type="text" class="datepicker<% $ShowTime ? ' withtime' : '' %> form-control"
% if ( $id ) {
id="<% $id %>"
% }
% if ( $Required ) {
required
% }
name="<% $Name %>" value="<% $Default %>" size="<% $Size %>" autocomplete="off" />
% $m->callback( %ARGS, Name => $Name, CallbackName => 'AfterDateInput', Object => $Object, ARGSRef => $ARGSRef, );
Expand Down Expand Up @@ -78,4 +81,5 @@ $Size => 16
$Object => undef
$ARGSRef => undef
$id => undef
$Required => undef
</%args>
3 changes: 2 additions & 1 deletion share/html/Widgets/ComboBox
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ my $z_index = 9999;
</%once>

<div class="combobox-wrapper" data-name="<% $Name %>" data-value="<% $Default // '' %>">
<select class="form-control combobox" size="<% $Rows %>">
<select class="form-control combobox" size="<% $Rows %>" <% $Required ? 'required' : '' %>>
<option value=""></option>
% for my $value (@Values) {
<option value="<% $value %>" <% ($Default // '') eq $value ? 'selected="selected"' : '' %>><% $value%></option>
Expand All @@ -65,4 +65,5 @@ $Rows => 5
$Default => ''
@Values => ()
$Class => ''
$Required => undef
</%ARGS>

0 comments on commit e27523f

Please sign in to comment.