Fix shopping list edit form - product was not prefilled (fixes #115)

This commit is contained in:
Bernd Bestel 2018-11-26 19:37:17 +01:00
parent e92d74f5c3
commit 5cdf2c14d3
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
4 changed files with 13 additions and 8 deletions

View File

@ -75,6 +75,11 @@ if (typeof prefillProduct !== "undefined")
}
var prefillProductId = GetUriParam("product");
var prefillProductId2 = Grocy.Components.ProductPicker.GetPicker().parent().data('prefill-by-id').toString();
if (!prefillProductId2.isEmpty())
{
prefillProductId = prefillProductId2;
}
if (typeof prefillProductId !== "undefined")
{
$('#product_id').val(prefillProductId);

View File

@ -59,14 +59,11 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
});
Grocy.FrontendHelpers.ValidateForm('shoppinglist-form');
Grocy.Components.ProductPicker.GetInputElement().focus();
if (Grocy.Components.ProductPicker.InProductAddWorkflow() === false)
if (Grocy.EditMode === "edit")
{
Grocy.Components.ProductPicker.GetInputElement().focus();
}
else
{
Grocy.Components.ProductPicker.GetPicker().trigger('change');
Grocy.Components.ProductPicker.GetPicker().trigger('change');
}
$('#amount').on('focus', function(e)

View File

@ -4,9 +4,10 @@
@php if(empty($disallowAddProductWorkflows)) { $disallowAddProductWorkflows = false; } @endphp
@php if(empty($prefillByName)) { $prefillByName = ''; } @endphp
@php if(empty($prefillById)) { $prefillById = ''; } @endphp
@php if(!isset($isRequired)) { $isRequired = true; } @endphp
<div class="form-group" data-next-input-selector="{{ $nextInputSelector }}" data-disallow-add-product-workflows="{{ BoolToString($disallowAddProductWorkflows) }}" data-prefill-by-name="{{ $prefillByName }}">
<div class="form-group" data-next-input-selector="{{ $nextInputSelector }}" data-disallow-add-product-workflows="{{ BoolToString($disallowAddProductWorkflows) }}" data-prefill-by-name="{{ $prefillByName }}" data-prefill-by-id="{{ $prefillById }}">
<label for="product_id">{{ $L('Product') }} <i class="fas fa-barcode"></i><span id="barcode-lookup-disabled-hint" class="small text-muted d-none"> {{ $L('Barcode lookup is disabled') }}</span></label>
<select class="form-control product-combobox" id="product_id" name="product_id" @if($isRequired) required @endif>
<option value=""></option>

View File

@ -21,10 +21,12 @@
<form id="shoppinglist-form" novalidate>
@php if($mode == 'edit') { $productId = $listItem->product_id; } else { $productId = ''; } @endphp
@include('components.productpicker', array(
'products' => $products,
'nextInputSelector' => '#amount',
'isRequired' => false
'isRequired' => false,
'prefillById' => $productId
))
@php if($mode == 'edit') { $value = $listItem->amount; } else { $value = 1; } @endphp