Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Set the ingredient ID after clicking on a result from the autocompleter

Roland Geider1b0678c860f7
diff --git a/manager/static/js/workout-manager.js b/manager/static/js/workout-manager.js
index 0b4d3aa35..d6d04f6ae 100644
--- a/manager/static/js/workout-manager.js
+++ b/manager/static/js/workout-manager.js
@@ -209,12 +209,12 @@ function init_ingredient_autocompleter()
{
// Init the autocompleter
$("#id_ingredient_freetext").autocomplete({
- source: "/nutrition/ingredient/search/%}",
+ source: "/nutrition/ingredient/search/",
minLength: 2,
select: function(event, ui) {
- // TODO: do something with the result
- // result ID can be accessed with ui.item.id
+ // After clicking on a result set the value of the hidden field
+ $('#id_ingredient').val(ui.item.id);
}
});
}
diff --git a/nutrition/templates/edit_meal_item.html b/nutrition/templates/edit_meal_item.html
index 66fc62525..89dbc395d 100644
--- a/nutrition/templates/edit_meal_item.html
+++ b/nutrition/templates/edit_meal_item.html
@@ -34,6 +34,8 @@ $(document).ready(function() {
{% comment %}
{% include "form_snippet.html" with field=form.ingredient css_class="ym-fbox-select" %}
{% endcomment %}
+
+ <input type="hidden" id="id_ingredient" name="ingredient">
{% include "form_snippet.html" with field=form.ingredient_freetext %}
<tr>
<td><input type="submit" value="{% trans "Save" %}" /></td>
diff --git a/nutrition/views.py b/nutrition/views.py
index 23be9d2c7..955ed0e47 100644
--- a/nutrition/views.py
+++ b/nutrition/views.py
@@ -291,6 +291,8 @@ def edit_meal_item(request, id, meal_id, item_id=None):
meal_item.save()
return HttpResponseRedirect('/nutrition/%s/view/' % id)
+ #else:
+ # logger.debug(meal_form.errors)
else:
meal_form = MealItemForm(instance=meal_item)
template_data['form'] = meal_form
@@ -414,4 +416,4 @@ def ingredient_search(request):
template_data['search_term'] = q
return render_to_response('ingredient_search.html',
template_data,
- context_instance=RequestContext(request))
\ No newline at end of file
+ context_instance=RequestContext(request))