mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
add js cleanGetUrl
This commit is contained in:
parent
23a686fe6c
commit
845e0c801d
BIN
netbox/project-static/dist/lldp.js
vendored
BIN
netbox/project-static/dist/lldp.js
vendored
Binary file not shown.
BIN
netbox/project-static/dist/netbox.js.map
vendored
BIN
netbox/project-static/dist/netbox.js.map
vendored
Binary file not shown.
@ -14,6 +14,9 @@ import { initRackElevation } from './racks';
|
|||||||
import { initLinks } from './links';
|
import { initLinks } from './links';
|
||||||
import { initHtmx } from './htmx';
|
import { initHtmx } from './htmx';
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
import { cleanGetUrl } from './util';
|
||||||
|
|
||||||
function initDocument(): void {
|
function initDocument(): void {
|
||||||
for (const init of [
|
for (const init of [
|
||||||
initBootstrap,
|
initBootstrap,
|
||||||
|
@ -477,3 +477,31 @@ export function replaceAll(input: string, pattern: string | RegExp, replacement:
|
|||||||
|
|
||||||
return input.replace(pattern, replacement);
|
return input.replace(pattern, replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable empty FormElemnts before submitting the form.
|
||||||
|
*
|
||||||
|
* @param targetform HTMLFormElement where the FormElements need to be disabled.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function cleanGetUrl(targetform: HTMLFormElement) {
|
||||||
|
|
||||||
|
var form_elements = targetform.elements;
|
||||||
|
|
||||||
|
for (const element of form_elements) {
|
||||||
|
// The SELECT statement requires a different approach. It depends on the selectedIndex, rather that the value.
|
||||||
|
switch (element.nodeName) {
|
||||||
|
case "SELECT":
|
||||||
|
const selectElement = element as HTMLSelectElement;
|
||||||
|
if (selectElement.selectedIndex == null || selectElement.selectedIndex == -1 || selectElement[selectElement.selectedIndex].getAttribute('value') == '') {
|
||||||
|
element.setAttribute('disabled','');
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (element.getAttribute('value') == null) {
|
||||||
|
element.setAttribute('disabled','');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,7 @@
|
|||||||
{% load form_helpers %}
|
{% load form_helpers %}
|
||||||
{% load helpers %}
|
{% load helpers %}
|
||||||
|
|
||||||
<script>
|
<form action="." method="get" onsubmit="return cleanGetUrl(this)">
|
||||||
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>
|
|
||||||
|
|
||||||
<form action="." method="get" onsubmit="return cleangeturl(this)">
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body overflow-visible d-flex flex-wrap justify-content-between py-3">
|
<div class="card-body overflow-visible d-flex flex-wrap justify-content-between py-3">
|
||||||
{% for field in filter_form.hidden_fields %}
|
{% for field in filter_form.hidden_fields %}
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col col-12 col-lg-6 offset-lg-3">
|
<div class="col col-12 col-lg-6 offset-lg-3">
|
||||||
<form action="{% url 'search' %}" method="get" class="form form-horizontal">
|
<form action="{% url 'search' %}" method="get" class="form form-horizontal" onsubmit="return cleanGetUrl(this)">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">
|
<h5 class="card-header">
|
||||||
Search
|
Search
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<form class="input-group" action="{% url 'search' %}" method="get">
|
<form class="input-group" action="{% url 'search' %}" method="get" onsubmit="return util.cleanGetUrl(this)">
|
||||||
<input
|
<input
|
||||||
name="q"
|
name="q"
|
||||||
type="text"
|
type="text"
|
||||||
|
Loading…
Reference in New Issue
Block a user