Skip to content

Commit

Permalink
Merge pull request #162 from semantic-systems/hotfix/prevent-empty-se…
Browse files Browse the repository at this point in the history
…arch

prevent empty search
  • Loading branch information
huntila authored Sep 1, 2023
2 parents c6025fc + a9fdf21 commit 808cb7c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 2 additions & 1 deletion templates/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div>
<div class="d-inline-block">
{% if search_term %}
<form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3" action="/results" method="GET">
<form name="searchbox" class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3" action="/results" method="GET" onsubmit="return emptySearch()">
<!-- <input type="search" class="form-control" placeholder="Search..." aria-label="Search"> -->
<div>
<div class="searchbox">
Expand All @@ -21,6 +21,7 @@
<input class="form-control" aria-label="Search for Article, Researcher"
autocomplete="off" inputmode="search" placeholder="Search for Article, Researcher"
type="search" name="txtSearchTerm" value="{{search_term}}" />
<div class="text-secondary" id="emptySearch" style="padding-left: 50px;"></div>
</div>
</div>
</form>
Expand Down
13 changes: 11 additions & 2 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div id='mainContent' class="container">

<div class="bsearch">
<form action="/results" method="GET">
<form name="searchbox" action="/results" method="GET" onsubmit="return emptySearch()">
<div class="">
<h2 class="text-center text-dark fs-1 fw-bold mb-4">Welcome to NFDI4DS Gateway</h2>
<div class="row mb-4">
Expand All @@ -32,9 +32,10 @@ <h4 class="text-secondary">The vision of NFDI4DS is to support all
</svg>
<input aria-label="Search for Articles and Researchers" autocomplete="off" inputmode="search"
placeholder="Search" type="search" name="txtSearchTerm" />
<div class="text-secondary" id="emptySearch" style="padding-left: 50px;"></div>
</div>
<!--sample search terms-->
<div class="d-flex justify-content-center mt-2">
<div class="d-flex justify-content-center mt-4">
<span class="m-2">Search Tips:</span>
<a href="/results?txtSearchTerm=Ricardo+Usbeck" class="btn btn-success btn-sm m-2"
role="button">Ricardo Usbeck</a>
Expand Down Expand Up @@ -236,6 +237,14 @@ <h2 class="text-center text-dark fs-1 fw-bold mt-5 mb-2">Partners</h2>

<script>

function emptySearch() {
var search = document.forms["searchbox"]["txtSearchTerm"].value;
if (search == "" || search == null || !/\S/.test(search)) {
document.getElementById("emptySearch").innerHTML = "\u2B11" + "Please enter a search term";
return false;
}
}

</script>

{% endblock javascripts %}
8 changes: 8 additions & 0 deletions templates/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@

});

function emptySearch() {
var search = document.forms["searchbox"]["txtSearchTerm"].value;
if (search == "" || search == null || !/\S/.test(search)) {
document.getElementById("emptySearch").innerHTML = "\u2B11" + "Please enter a search term";
return false;
}
}




Expand Down

0 comments on commit 808cb7c

Please sign in to comment.