Просмотр исходного кода

Fixes #18955: Include the "clear" button only for non-required dropdown fields (#18971)

* Include the 'clear' button only for non-required fields

* Apply the 'required' attribute for mandatory <select> fields

* Recompile static assets
Jeremy Stretch 10 месяцев назад
Родитель
Сommit
6ed41f6680

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
netbox/project-static/dist/netbox.js


Разница между файлами не показана из-за своего большого размера
+ 0 - 0
netbox/project-static/dist/netbox.js.map


+ 7 - 5
netbox/project-static/src/select/config.ts

@@ -5,11 +5,13 @@ interface PluginConfig {
 export function getPlugins(element: HTMLSelectElement): object {
   const plugins: PluginConfig = {};
 
-  // Enable "clear all" button
-  plugins.clear_button = {
-    html: (data: Dict) =>
-      `<i class="mdi mdi-close-circle ${data.className}" title="${data.title}"></i>`,
-  };
+  // Enable "clear all" button for non-required fields
+  if (!element.required) {
+    plugins.clear_button = {
+      html: (data: Dict) =>
+        `<i class="mdi mdi-close-circle ${data.className}" title="${data.title}"></i>`,
+    };
+  }
 
   // Enable individual "remove" buttons for items on multi-select fields
   if (element.hasAttribute('multiple')) {

+ 1 - 1
netbox/templates/django/forms/widgets/select.html

@@ -1,4 +1,4 @@
-<select name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} class="form-select {% if 'class' in widget.attrs %} {{ widget.attrs.class }}{% endif %}">{% for group_name, group_choices, group_index in widget.optgroups %}{% if group_name %}
+<select name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %} class="form-select{% if 'class' in widget.attrs %} {{ widget.attrs.class }}{% endif %}"{% if widget.required %} required{% endif %}>{% for group_name, group_choices, group_index in widget.optgroups %}{% if group_name %}
   <optgroup label="{{ group_name }}">{% endif %}{% for option in group_choices %}
   {% include option.template_name with widget=option %}{% endfor %}{% if group_name %}
   </optgroup>{% endif %}{% endfor %}

Некоторые файлы не были показаны из-за большого количества измененных файлов