mirror of
https://github.com/grocy/grocy.git
synced 2025-08-06 06:22:52 +00:00
Hide barcode in select dropdown but search in it
This commit is contained in:
parent
dc530c80aa
commit
83a7534a74
5
grocy.js
5
grocy.js
@ -75,3 +75,8 @@ Grocy.EmptyElementWhenMatches = function(selector, text)
|
|||||||
$(selector).text('');
|
$(selector).text('');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
String.prototype.contains = function(search)
|
||||||
|
{
|
||||||
|
return this.toLowerCase().indexOf(search.toLowerCase()) !== -1;
|
||||||
|
};
|
||||||
|
@ -88,7 +88,28 @@ $('#product_id').on('change', function(e)
|
|||||||
|
|
||||||
$(function()
|
$(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);
|
$('#amount').val(1);
|
||||||
$('#product_id').val('');
|
$('#product_id').val('');
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<select data-instockproduct="instockproduct" class="form-control combobox" id="product_id" name="product_id" required>
|
<select data-instockproduct="instockproduct" class="form-control combobox" id="product_id" name="product_id" required>
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<?php foreach ($products as $product) : ?>
|
<?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; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<div id="product-error" class="help-block with-errors"></div>
|
<div id="product-error" class="help-block with-errors"></div>
|
||||||
|
@ -42,7 +42,7 @@ $(function()
|
|||||||
Grocy.FetchJson('/api/get-object/products/' + Grocy.EditObjectId,
|
Grocy.FetchJson('/api/get-object/products/' + Grocy.EditObjectId,
|
||||||
function (product)
|
function (product)
|
||||||
{
|
{
|
||||||
if (product.barcode.length > 0)
|
if (product.barcode !== null && product.barcode.length > 0)
|
||||||
{
|
{
|
||||||
product.barcode.split(',').forEach(function(item)
|
product.barcode.split(',').forEach(function(item)
|
||||||
{
|
{
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
<textarea class="form-control" rows="2" id="description" name="description"><?php if ($mode == 'edit') echo $product->description; ?></textarea>
|
<textarea class="form-control" rows="2" id="description" name="description"><?php if ($mode == 'edit') echo $product->description; ?></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group tm-group">
|
<div class="form-group tm-group">
|
||||||
<label for="barcode-taginput">Barcode(s)</label>
|
<label for="barcode-taginput">Barcode(s) <i class="fa fa-barcode"></i></label>
|
||||||
<input type="text" class="form-control tm-input" id="barcode-taginput" placeholder="Add (scan) a barcode here to add one...">
|
<input type="text" class="form-control tm-input" id="barcode-taginput">
|
||||||
<div id="barcode-taginput-container"></div>
|
<div id="barcode-taginput-container"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -90,7 +90,28 @@ $(function()
|
|||||||
});
|
});
|
||||||
$('.datepicker').trigger('change');
|
$('.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);
|
$('#amount').val(1);
|
||||||
$('#best_before_date').val('');
|
$('#best_before_date').val('');
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<select class="form-control combobox" id="product_id" name="product_id" required>
|
<select class="form-control combobox" id="product_id" name="product_id" required>
|
||||||
<option value=""></option>
|
<option value=""></option>
|
||||||
<?php foreach ($products as $product) : ?>
|
<?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; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<div class="help-block with-errors"></div>
|
<div class="help-block with-errors"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user