Hide barcode in select dropdown but search in it

This commit is contained in:
Bernd Bestel 2017-04-18 23:04:26 +02:00
parent dc530c80aa
commit 83a7534a74
7 changed files with 54 additions and 7 deletions

View File

@ -75,3 +75,8 @@ Grocy.EmptyElementWhenMatches = function(selector, text)
$(selector).text('');
}
};
String.prototype.contains = function(search)
{
return this.toLowerCase().indexOf(search.toLowerCase()) !== -1;
};

View File

@ -88,7 +88,28 @@ $('#product_id').on('change', function(e)
$(function()
{
$('.combobox').combobox({ appendId: '_text_input' });
$('.combobox').combobox({
appendId: '_text_input',
matcher: function(text)
{
var input = $('#product_id_text_input').val();
var optionElement = $("#product_id option:contains('" + text + "')").first();
var additionalSearchdata = optionElement.data('additional-searchdata');
if (text.contains(input))
{
return true;
}
else if (additionalSearchdata !== null && additionalSearchdata.length > 0)
{
return additionalSearchdata.contains(input);
}
else
{
return false;
}
}
});
$('#amount').val(1);
$('#product_id').val('');

View File

@ -7,7 +7,7 @@
<select data-instockproduct="instockproduct" class="form-control combobox" id="product_id" name="product_id" required>
<option value=""></option>
<?php foreach ($products as $product) : ?>
<option value="<?php echo $product->id; ?>"><?php echo $product->name; ?><?php if (!empty($product->barcode)) echo ' [' . $product->barcode . ']'; ?></option>
<option data-additional-searchdata="<?php echo $product->barcode; ?>" value="<?php echo $product->id; ?>"><?php echo $product->name; ?></option>
<?php endforeach; ?>
</select>
<div id="product-error" class="help-block with-errors"></div>

View File

@ -42,7 +42,7 @@ $(function()
Grocy.FetchJson('/api/get-object/products/' + Grocy.EditObjectId,
function (product)
{
if (product.barcode.length > 0)
if (product.barcode !== null && product.barcode.length > 0)
{
product.barcode.split(',').forEach(function(item)
{

View File

@ -18,8 +18,8 @@
<textarea class="form-control" rows="2" id="description" name="description"><?php if ($mode == 'edit') echo $product->description; ?></textarea>
</div>
<div class="form-group tm-group">
<label for="barcode-taginput">Barcode(s)</label>
<input type="text" class="form-control tm-input" id="barcode-taginput" placeholder="Add (scan) a barcode here to add one...">
<label for="barcode-taginput">Barcode(s)&nbsp;&nbsp;<i class="fa fa-barcode"></i></label>
<input type="text" class="form-control tm-input" id="barcode-taginput">
<div id="barcode-taginput-container"></div>
</div>
<div class="form-group">

View File

@ -90,7 +90,28 @@ $(function()
});
$('.datepicker').trigger('change');
$('.combobox').combobox({ appendId: '_text_input' });
$('.combobox').combobox({
appendId: '_text_input',
matcher: function(text)
{
var input = $('#product_id_text_input').val();
var optionElement = $("#product_id option:contains('" + text + "')").first();
var additionalSearchdata = optionElement.data('additional-searchdata');
if (text.contains(input))
{
return true;
}
else if (additionalSearchdata !== null && additionalSearchdata.length > 0)
{
return additionalSearchdata.contains(input);
}
else
{
return false;
}
}
});
$('#amount').val(1);
$('#best_before_date').val('');

View File

@ -7,7 +7,7 @@
<select class="form-control combobox" id="product_id" name="product_id" required>
<option value=""></option>
<?php foreach ($products as $product) : ?>
<option value="<?php echo $product->id; ?>"><?php echo $product->name; ?><?php if (!empty($product->barcode)) echo ' [' . $product->barcode . ']'; ?></option>
<option data-additional-searchdata="<?php echo $product->barcode; ?>" value="<?php echo $product->id; ?>"><?php echo $product->name; ?></option>
<?php endforeach; ?>
</select>
<div class="help-block with-errors"></div>