Wir haben Habits udn Checkboxen fried chicken

This commit is contained in:
nikolaswollenberg 2024-01-26 08:27:44 +01:00
parent f66d03c84d
commit 4bc17623bb
2 changed files with 33 additions and 1 deletions

5
app.py
View File

@ -219,6 +219,11 @@ def habit_create():
errors=errors, errors=errors,
)""" )"""
@app.route('/check', methods=['POST'])
@login_required
def check_habit():
habit = request.get_json()["habitId"]
return {}
# Run the application # Run the application
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -85,7 +85,7 @@
{% for habit in habits %} {% for habit in habits %}
<li class="row col-md-4"> <li class="row col-md-4">
<div class="col-auto"> <div class="col-auto">
<input type="checkbox" class="task-checkbox" id="{{habit.id}}"> <input type="checkbox" class="task-checkbox" id="{{habit.id}}" onclick="sendPostRequest('{{habit.id}}')">
</div> </div>
<div class="col" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis"> <div class="col" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis">
@ -101,6 +101,33 @@
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
<script>
function sendPostRequest(checkboxId) {
// Get the checkbox element using the provided ID
var checkbox = document.getElementById(checkboxId);
console.log(checkbox);
// Check if the checkbox is checked
if (checkbox.checked) {
// Get the habit id from the checkbox id attribute
var habitId = checkboxId;
// Make a POST request to /check with the habit id
axios.post('/check', { habitId: habitId }, {
headers: {
'Content-Type': 'application/json'
}
})
.then(function (response) {
// Handle the success response if needed
console.log(response.data);
})
.catch(function (error) {
// Handle the error if needed
console.error('Error:', error);
});
}
}
</script>
</div> </div>
{% endblock %} {% endblock %}