mirror of https://github.com/kcal-app/kcal.git
Ensure ingredients list always has a weight entry
This commit is contained in:
parent
d91c26159b
commit
594f5c6e4b
|
|
@ -133,7 +133,7 @@
|
||||||
@include('recipes.partials.separator-input', $item)
|
@include('recipes.partials.separator-input', $item)
|
||||||
@endif
|
@endif
|
||||||
@empty
|
@empty
|
||||||
@include('recipes.partials.ingredient-input')
|
@include('recipes.partials.ingredient-input', ['weight' => 0])
|
||||||
@endforelse
|
@endforelse
|
||||||
<div class="templates hidden">
|
<div class="templates hidden">
|
||||||
<div class="ingredient-template">
|
<div class="ingredient-template">
|
||||||
|
|
@ -255,10 +255,17 @@
|
||||||
const newNode = template.cloneNode(true).firstElementChild;
|
const newNode = template.cloneNode(true).firstElementChild;
|
||||||
|
|
||||||
// Set weight based on previous sibling.
|
// Set weight based on previous sibling.
|
||||||
|
const weightField = newNode.querySelector('input[name$="[weight][]"]');
|
||||||
|
if (templates.previousElementSibling) {
|
||||||
const lastWeight = templates.previousElementSibling.querySelector('input[name$="[weight][]"]');
|
const lastWeight = templates.previousElementSibling.querySelector('input[name$="[weight][]"]');
|
||||||
if (lastWeight && lastWeight.value) {
|
if (lastWeight && lastWeight.value) {
|
||||||
newNode.querySelector('input[name$="[weight][]"]').value = Number.parseInt(lastWeight.value) + 1;
|
weightField.value = Number.parseInt(lastWeight.value) + 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
weightField.value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Insert new node before templates.
|
// Insert new node before templates.
|
||||||
$el.insertBefore(newNode, templates);
|
$el.insertBefore(newNode, templates);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue