From fd38390c5deddc591e0bebd3d9bfb812d06fc5c6 Mon Sep 17 00:00:00 2001 From: sunnavy Date: Fri, 3 Nov 2023 13:27:24 -0400 Subject: [PATCH] Add "required" attribute for mandatory custom field inputs The attribute isn't enabled for "List" style of multi-value select custom fields: "required" means each "required" checkbox must be checked, but we want to allow to check just some of them. For mandatory select inputs, previously in a67e05ea49 we chose to keep "(no value)" as the initial state to force user to manually select one valid option. This commit implements the logic in js, and there is no need to keep the invalid "(no value)" option any more. --- share/html/Admin/CustomFields/Modify.html | 2 +- share/html/Admin/Queues/DefaultValues.html | 12 +++++++++++- share/html/Elements/EditCustomField | 1 + share/html/Elements/EditCustomFieldAutocomplete | 10 +++++++++- share/html/Elements/EditCustomFieldBinary | 7 ++++++- share/html/Elements/EditCustomFieldCombobox | 2 ++ share/html/Elements/EditCustomFieldDate | 3 ++- share/html/Elements/EditCustomFieldDateTime | 3 ++- share/html/Elements/EditCustomFieldFreeform | 7 +++++++ share/html/Elements/EditCustomFieldHTML | 4 ++++ share/html/Elements/EditCustomFieldImage | 7 ++++++- share/html/Elements/EditCustomFieldSelect | 13 ++++++------- share/html/Elements/EditCustomFieldText | 4 ++++ share/html/Elements/EditCustomFieldWikitext | 4 ++++ share/html/Elements/EditCustomFields | 1 + share/html/Elements/SelectDate | 4 ++++ share/html/Widgets/ComboBox | 3 ++- share/static/js/cascaded.js | 5 +++++ share/static/js/util.js | 10 ++++++++++ 19 files changed, 87 insertions(+), 15 deletions(-) diff --git a/share/html/Admin/CustomFields/Modify.html b/share/html/Admin/CustomFields/Modify.html index 6e35d8da722..904eaea04d4 100644 --- a/share/html/Admin/CustomFields/Modify.html +++ b/share/html/Admin/CustomFields/Modify.html @@ -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 &> % } diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html index 0cde0c46ddd..3f69b0fb2ec 100644 --- a/share/html/Admin/Queues/DefaultValues.html +++ b/share/html/Admin/Queues/DefaultValues.html @@ -68,6 +68,8 @@ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes, Grouping => 'Basics', CategoryObj => $queue, + ShowEmptyOption => 1, + Required => 0, &> <&| /Elements/LabeledValue, Label => loc('Article') &> @@ -91,6 +93,8 @@ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes, Grouping => 'Dates', CategoryObj => $queue, + ShowEmptyOption => 1, + Required => 0, &> @@ -103,6 +107,8 @@ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes, Grouping => 'People', CategoryObj => $queue, + ShowEmptyOption => 1, + Required => 0, &> @@ -116,6 +122,8 @@ CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes, Grouping => 'Links', CategoryObj => $queue, + ShowEmptyOption => 1, + Required => 0, &> @@ -126,11 +134,13 @@ Object => RT::Ticket->new($session{CurrentUser}), Groupings => \@groupings, CategoryObj => $queue, + ShowEmptyOption => 1, + Required => 0, &>
<&|/Widgets/TitleBox, title => loc("Transaction Custom Fields"), content_class => 'mx-auto width-sm' &> - <& /Elements/EditCustomFields, CustomFields => $queue->TicketTransactionCustomFields->LimitToDefaultValuesSupportedTypes, Object => RT::Transaction->new($session{CurrentUser}), QueueObj => $queue, &> + <& /Elements/EditCustomFields, CustomFields => $queue->TicketTransactionCustomFields->LimitToDefaultValuesSupportedTypes, Object => RT::Transaction->new($session{CurrentUser}), QueueObj => $queue, ShowEmptyOption => 1, Required => 0 &>
diff --git a/share/html/Elements/EditCustomField b/share/html/Elements/EditCustomField index c088917ee70..b2e75720642 100644 --- a/share/html/Elements/EditCustomField +++ b/share/html/Elements/EditCustomField @@ -162,4 +162,5 @@ $Rows => 5 $Cols => 15 $Default => undef $DefaultsFromTopArguments => 1, +$Required => undef diff --git a/share/html/Elements/EditCustomFieldAutocomplete b/share/html/Elements/EditCustomFieldAutocomplete index 40104555ae7..2acef923d7c 100644 --- a/share/html/Elements/EditCustomFieldAutocomplete +++ b/share/html/Elements/EditCustomFieldAutocomplete @@ -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 || '' %>