Always show trash icon; clear text when removing sole asset
The remove button is now always visible. Clicking it on the only
asset row clears the field rather than deleting the row, so there's
always an input present. Switches the input to x-model so clearing
state also clears the visible text.
diff --git a/lib/views/capture.rb b/lib/views/capture.rb
index e63bd9f..18789e3 100644
--- a/lib/views/capture.rb
+++ b/lib/views/capture.rb
@@ -127,13 +127,12 @@ module Domus
type: "text",
name: "asset_names[]",
placeholder: "Asset name",
- "@keydown.enter.prevent": "addAsset()",
- "@input": "assetNames[i] = $event.target.value"
+ "x-model": "assetNames[i]",
+ "@keydown.enter.prevent": "addAsset()"
)
button(
type: "button",
class: "btn-remove-asset",
- "x-show": "assetNames[i] || assetNames.length > 1",
"@click": "removeAsset(i)"
) { icon("trash") }
end
diff --git a/public/capture.js b/public/capture.js
index f7084b6..2bb3172 100644
--- a/public/capture.js
+++ b/public/capture.js
@@ -34,8 +34,11 @@ function captureApp() {
},
removeAsset(i) {
- this.assetNames.splice(i, 1);
- if (this.assetNames.length === 0) this.assetNames.push('');
+ if (this.assetNames.length === 1) {
+ this.assetNames[0] = '';
+ } else {
+ this.assetNames.splice(i, 1);
+ }
},
onSubmit() {