Modularize product picker

This commit is contained in:
Bernd Bestel
2018-07-14 14:43:57 +02:00
parent aa0771877f
commit 71fc49252f
10 changed files with 239 additions and 328 deletions

View File

@@ -30,7 +30,7 @@
}
});
$('#product_id').on('change', function(e)
Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{
var productId = $(e.target).val();
@@ -52,39 +52,22 @@ $('#product_id').on('change', function(e)
}
});
$('.combobox').combobox({
appendId: '_text_input'
});
$('#product_id_text_input').on('change', function(e)
{
var input = $('#product_id_text_input').val().toString();
var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first();
if (possibleOptionElement.length > 0 && possibleOptionElement.text().length > 0)
{
$('#product_id').val(possibleOptionElement.val());
$('#product_id').data('combobox').refresh();
$('#product_id').trigger('change');
}
});
$('#product_id_text_input').focus();
$('#product_id_text_input').trigger('change');
if (Grocy.EditMode === 'edit')
{
$('#product_id').addClass('suppress-next-custom-validate-event');
$('#product_id').trigger('change');
}
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
}
$('#amount').on('focus', function(e)
{
if ($('#product_id_text_input').val().length === 0)
if (Grocy.Components.ProductPicker.GetValue().length === 0)
{
$('#product_id_text_input').focus();
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{