mirror of
https://github.com/sstent/foodplanner.git
synced 2026-03-17 10:45:30 +00:00
62 lines
2.8 KiB
HTML
62 lines
2.8 KiB
HTML
<!-- Add Meal Modal -->
|
|
<div class="modal fade" id="addMealModal" tabindex="-1" aria-labelledby="addMealModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="addMealModalLabel">Add Meal to <span id="mealTimeDisplay"></span></h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="addMealForm">
|
|
<input type="hidden" id="addMealTime" name="meal_time">
|
|
<input type="hidden" name="person" value="{{ person }}">
|
|
<input type="hidden" name="date" value="{{ current_date.isoformat() }}">
|
|
<div class="mb-3">
|
|
<label class="form-label">Select Meal</label>
|
|
<input type="text" class="form-control mb-2" id="mealSearchInput" placeholder="Search meals..." data-testid="meal-search-input">
|
|
<select class="form-control" name="meal_id" id="mealSelect" required size="10">
|
|
<option value="">Choose meal...</option>
|
|
{% for meal in meals %}
|
|
<option value="{{ meal.id }}" data-testid="meal-option">{{ meal.name }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="button" class="btn btn-primary" onclick="submitAddMeal()">Add Meal</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.getElementById('mealSearchInput').addEventListener('input', function() {
|
|
const searchText = this.value.toLowerCase();
|
|
const select = document.getElementById('mealSelect');
|
|
const options = select.options;
|
|
|
|
for (let i = 0; i < options.length; i++) {
|
|
const option = options[i];
|
|
if (option.value === "") continue; // Skip "Choose meal..."
|
|
|
|
const text = option.text.toLowerCase();
|
|
if (text.includes(searchText)) {
|
|
option.style.display = "";
|
|
} else {
|
|
option.style.display = "none";
|
|
}
|
|
}
|
|
});
|
|
|
|
// Reset search when modal is shown
|
|
document.getElementById('addMealModal').addEventListener('show.bs.modal', function () {
|
|
document.getElementById('mealSearchInput').value = '';
|
|
const options = document.getElementById('mealSelect').options;
|
|
for (let i = 0; i < options.length; i++) {
|
|
options[i].style.display = "";
|
|
}
|
|
});
|
|
</script>
|