mirror of https://github.com/kcal-app/kcal.git
Prefill journal entry values with previous entry data
This commit is contained in:
parent
35f386d681
commit
089b2edab2
|
@ -1448,6 +1448,11 @@
|
|||
"integrity": "sha1-l6ERlkmyEa0zaR2fn0hqjsn74KM=",
|
||||
"dev": true
|
||||
},
|
||||
"alpine-magic-helpers": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/alpine-magic-helpers/-/alpine-magic-helpers-0.5.1.tgz",
|
||||
"integrity": "sha512-zj1o/Er5WLCQbaDjQCsobrfPaxgHp6Mf2ZDXce7B4THrPdKXwOrIB4zHykjXA6qCEljyh4js2fA6QWLXp3w/nw=="
|
||||
},
|
||||
"alpinejs": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/alpinejs/-/alpinejs-2.8.0.tgz",
|
||||
|
|
|
@ -21,5 +21,8 @@
|
|||
"resolve-url-loader": "^3.1.0",
|
||||
"tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.0.1",
|
||||
"vue-template-compiler": "^2.6.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"alpine-magic-helpers": "^0.5.1"
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,4 @@
|
|||
require('./bootstrap');
|
||||
|
||||
require('alpine-magic-helpers');
|
||||
require('alpinejs');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div class="grid grid-cols-12 gap-4 items-center mt-2">
|
||||
<div x-data x-init="setDefaultsFromPrevious($el);" class="grid grid-cols-12 gap-4 items-center mt-2">
|
||||
<!-- Date -->
|
||||
<div class="col-span-2">
|
||||
<x-inputs.input class="block w-full"
|
||||
|
@ -44,9 +44,27 @@
|
|||
:default-name="$name ?? null" />
|
||||
</div>
|
||||
|
||||
<x-inputs.icon-button type="button" color="red" x-on:click="$event.target.parentNode.remove(); ingredients--;">
|
||||
<x-inputs.icon-button type="button" color="red" x-on:click="$parent.ingredients--; $event.target.parentNode.remove();">
|
||||
<svg class="h-8 w-8 pointer-events-none m-auto" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M9 2a1 1 0 00-.894.553L7.382 4H4a1 1 0 000 2v10a2 2 0 002 2h8a2 2 0 002-2V6a1 1 0 100-2h-3.382l-.724-1.447A1 1 0 0011 2H9zM7 8a1 1 0 012 0v6a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v6a1 1 0 102 0V8a1 1 0 00-1-1z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</x-inputs.icon-button>
|
||||
</div>
|
||||
|
||||
@once
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
let setDefaultsFromPrevious = ($el) => {
|
||||
let currentDateEl = $el.querySelector('input[name="ingredients[date][]"]');
|
||||
let currentMealEl = $el.querySelector('select[name="ingredients[meal][]"]');
|
||||
let previousEl = $el.previousElementSibling;
|
||||
let previousDateEl = previousEl.querySelector('input[name="ingredients[date][]"]');
|
||||
let previousMealEl = previousEl.querySelector('select[name="ingredients[meal][]"]');
|
||||
if (currentDateEl && currentMealEl && previousDateEl && previousMealEl) {
|
||||
currentDateEl.value = previousDateEl.value;
|
||||
currentMealEl.value = previousMealEl.value;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
@endonce
|
||||
|
|
Loading…
Reference in New Issue