Self hosted FLOSS fitness/workout, nutrition and weight tracker
Use new autocompleter for ingredient selection as well
Roland Geider764fb318cc0e
diff --git a/wger/nutrition/static/js/nutrition.js b/wger/nutrition/static/js/nutrition.jsindex 8c9228c7a..4f46c5b63 100644--- a/wger/nutrition/static/js/nutrition.js+++ b/wger/nutrition/static/js/nutrition.js@@ -70,17 +70,17 @@ function init_ingredient_detail(url)function init_ingredient_autocompleter(){// Init the autocompleter- $("#id_ingredient_searchfield").autocomplete({- source: '/api/v2/ingredient/search/',- minLength: 2,- select: function(event, ui) {+ $('#id_ingredient_searchfield').devbridgeAutocomplete({+ serviceUrl: '/api/v2/ingredient/search/',+ onSelect: function (suggestion) {+ var ingredient_id = suggestion.data.id;// After clicking on a result set the value of the hidden field- $('#id_ingredient').val(ui.item.id);- $('#exercise_name').html(ui.item.label);+ $('#id_ingredient').val(ingredient_id);+ $('#exercise_name').html(suggestion.value);// See if the ingredient has any units and set the values for the forms- $.get('/api/v2/ingredientweightunit/?ingredient=' + ui.item.id, function(unit_data) {+ $.get('/api/v2/ingredientweightunit/?ingredient=' + ingredient_id, function(unit_data) {// Remove any old units, if anyvar options = $('#id_weight_unit').find('option');@@ -100,6 +100,16 @@ function init_ingredient_autocompleter()});});});+ },+ paramName: 'term',+ transformResult: function(response) {+ // why is response not already a JSON object??+ var jsonResponse = $.parseJSON(response);+ return {+ suggestions: $.map(jsonResponse, function(item) {+ return {value: item.value, data: {id: item.id}};+ })+ };}});}