Added grocycode for recipes (closes #1562)

This commit is contained in:
Bernd Bestel
2022-02-11 17:49:30 +01:00
parent 51fdefaede
commit 222c518a5f
16 changed files with 212 additions and 16 deletions

View File

@@ -37,7 +37,7 @@ Grocy.Components.RecipePicker.Clear = function()
$('.recipe-combobox').combobox({
appendId: '_text_input',
bsVersion: '4',
clearIfNoMatch: true
clearIfNoMatch: false
});
var prefillByName = Grocy.Components.RecipePicker.GetPicker().parent().data('prefill-by-name').toString();
@@ -66,3 +66,38 @@ if (typeof prefillById !== "undefined")
var nextInputElement = $(Grocy.Components.RecipePicker.GetPicker().parent().data('next-input-selector').toString());
nextInputElement.focus();
}
$('#recipe_id_text_input').on('blur', function(e)
{
if ($('#recipe_id').hasClass("combobox-menu-visible"))
{
return;
}
var input = $('#recipe_id_text_input').val().toString();
var possibleOptionElement = [];
// grocycode handling
if (input.startsWith("grcy"))
{
var gc = input.split(":");
if (gc[1] == "r")
{
possibleOptionElement = $("#recipe_id option[value=\"" + gc[2] + "\"]").first();
}
if (possibleOptionElement.length > 0)
{
$('#recipe_id').val(possibleOptionElement.val());
$('#recipe_id').data('combobox').refresh();
$('#recipe_id').trigger('change');
}
else
{
$('#recipe_id').val(null);
$('#recipe_id_text_input').val("");
$('#recipe_id').data('combobox').refresh();
$('#recipe_id').trigger('change');
}
}
});