a ton of fun happened, refactored alot
This commit is contained in:
24
plugins/utility/search/templates/search/_form_scripts.html
Normal file
24
plugins/utility/search/templates/search/_form_scripts.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!-- File: plugins/utility/templates/search/_form_scripts.html -->
|
||||
{# Optional: include this partial if you use Select2 for tags autocomplete #}
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0/dist/css/select2.min.css" rel="stylesheet"/>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0/dist/js/select2.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('select[name="tags"]').select2({
|
||||
placeholder: 'Select tags',
|
||||
ajax: {
|
||||
url: '{{ url_for("search.search_tags") }}',
|
||||
dataType: 'json',
|
||||
delay: 250,
|
||||
data: params => ({ term: params.term }),
|
||||
processResults: data => ({
|
||||
results: data.map(name => ({ id: name, text: name }))
|
||||
}),
|
||||
cache: true
|
||||
},
|
||||
minimumInputLength: 1,
|
||||
allowClear: true
|
||||
});
|
||||
});
|
||||
</script>
|
45
plugins/utility/search/templates/search/search.html
Normal file
45
plugins/utility/search/templates/search/search.html
Normal file
@ -0,0 +1,45 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Search{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container mt-4">
|
||||
<h1 class="mb-3">Search Plants</h1>
|
||||
<form method="post" novalidate>
|
||||
{{ form.hidden_tag() }}
|
||||
<div class="form-group mb-3">
|
||||
{{ form.query.label(class="form-label") }}
|
||||
{{ form.query(class="form-control", placeholder="Enter search term…") }}
|
||||
{% if form.query.errors %}
|
||||
<div class="text-danger small">
|
||||
{{ form.query.errors[0] }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
{{ form.tags.label(class="form-label") }}
|
||||
{{ form.tags(class="form-select", multiple=true) }}
|
||||
{% if form.tags.errors %}
|
||||
<div class="text-danger small">
|
||||
{{ form.tags.errors[0] }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">{{ form.submit.label.text }}</button>
|
||||
</form>
|
||||
|
||||
<hr class="my-4">
|
||||
|
||||
{% if results %}
|
||||
<ul class="list-group">
|
||||
{% for plant in results %}
|
||||
<li class="list-group-item">
|
||||
<a href="{{ url_for('plant.view', plant_id=plant.id) }}">
|
||||
{{ plant.common_name or plant.scientific_name }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% elif request.method == 'POST' %}
|
||||
<p class="text-muted">No results found.</p>
|
||||
{% endif %}
|
||||
</div>
|
Reference in New Issue
Block a user