Remove 'empty' variables from url after search/filter #6973

Closed
opened 2025-12-29 19:47:22 +01:00 by adam · 3 comments
Owner

Originally created by @PieterL75 on GitHub (Sep 13, 2022).

Originally assigned to: @PieterL75 on GitHub.

NetBox version

v3.3.2

Feature type

Change to existing functionality

Proposed functionality

When a search or filter is done, the resulting page has an url with all possible fields.
It would be neater if only the field that has data is added to the url variable.
Especially when there are a lot of custom fields.

ex :
https://netbox/dcim/devices/?q=test&serial=&asset_tag=&mac_address=&device_type_id=79&console_ports=&console_server_ports=&power_ports=&power_outlets=&interfaces=&pass_through_ports=&has_primary_ip=&virtual_chassis_member=&local_context_data=&cf_hostname=&cf_ltag=&cf_observium=&cf_observium_id=&cf_reference=&cf_u_bios_uuid=&cf_warrantydate=

could be reduced to

https://netbox/dcim/devices/?q=test&device_type_id=79

Use case

When URLs are shared or stored, it gives a better view in what is going to be filtered.

Database changes

No response

External dependencies

No response

Originally created by @PieterL75 on GitHub (Sep 13, 2022). Originally assigned to: @PieterL75 on GitHub. ### NetBox version v3.3.2 ### Feature type Change to existing functionality ### Proposed functionality When a search or filter is done, the resulting page has an url with all possible fields. It would be neater if only the field that has data is added to the url variable. Especially when there are a lot of custom fields. ex : https://netbox/dcim/devices/?q=test&serial=&asset_tag=&mac_address=&device_type_id=79&console_ports=&console_server_ports=&power_ports=&power_outlets=&interfaces=&pass_through_ports=&has_primary_ip=&virtual_chassis_member=&local_context_data=&cf_hostname=&cf_ltag=&cf_observium=&cf_observium_id=&cf_reference=&cf_u_bios_uuid=&cf_warrantydate= could be reduced to https://netbox/dcim/devices/?q=test&device_type_id=79 ### Use case When URLs are shared or stored, it gives a better view in what is going to be filtered. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 19:47:22 +01:00
adam closed this issue 2025-12-29 19:47:22 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 13, 2022):

This is an artifact of how web browsers process forms with GET actions. I'm not aware of anything we can do to suppress the extraneous parameters natively; it would require extending the submission process with a Javascript function that determines which fields to append to the URL string based on their values.

@jeremystretch commented on GitHub (Sep 13, 2022): This is an artifact of how web browsers process forms with GET actions. I'm not aware of anything we can do to suppress the extraneous parameters natively; it would require extending the submission process with a Javascript function that determines which fields to append to the URL string based on their values.
Author
Owner

@PieterL75 commented on GitHub (Sep 16, 2022):

Solution is to add this to the filter_list.html

<script>
function cleangeturl(form) {
  
  var form_elements = form.elements;
  
  for (var i=0; i<form_elements.length; i++ ) {
    var element = form_elements[i]
    if (element.name && element.value == '') {
      element.disabled=true;
    }
  }
</script>

and update the <form with

<form action="." method="get" onsubmit="return cleangeturl(this)">
@PieterL75 commented on GitHub (Sep 16, 2022): Solution is to add this to the filter_list.html ``` <script> function cleangeturl(form) { var form_elements = form.elements; for (var i=0; i<form_elements.length; i++ ) { var element = form_elements[i] if (element.name && element.value == '') { element.disabled=true; } } </script> ``` and update the <form with ``` <form action="." method="get" onsubmit="return cleangeturl(this)"> ```
Author
Owner

@jeremystretch commented on GitHub (Sep 26, 2022):

@PieterL75 I agree with the general approach, however our intent is to build all Javascript from Typescript compiled into central libraries, rather than embedding JS directly within each page.

@jeremystretch commented on GitHub (Sep 26, 2022): @PieterL75 I agree with the general approach, however our intent is to build all Javascript from Typescript compiled into central libraries, rather than embedding JS directly within each page.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6973