mirror of
https://github.com/grocy/grocy.git
synced 2025-08-19 03:40:10 +00:00
Added grocycode for recipes (closes #1562)
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user