From e8f4ff5c9d11e13baf8d2b707c5d3a8817f8d835 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 29 Mar 2024 00:50:46 +0000 Subject: [PATCH] Set a maximum count number for each counter --- assets/js/controllers/count_controller.js | 7 +++++++ public/index.html | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/assets/js/controllers/count_controller.js b/assets/js/controllers/count_controller.js index 2d93cbb..97f29d6 100644 --- a/assets/js/controllers/count_controller.js +++ b/assets/js/controllers/count_controller.js @@ -6,6 +6,7 @@ export default class extends Controller { static values = { canBeNegative: Boolean, count: Number, + maximumCountNumber: Number, }; connect() { @@ -33,6 +34,12 @@ export default class extends Controller { increment() { console.log("count#increment"); + const maximumCountNumber = this.maximumCountNumberValue || 10; + + if (this.countValue === maximumCountNumber) { + return; + } + this.countValue = this.countValue + 1; } } diff --git a/public/index.html b/public/index.html index b11de50..edf95f8 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,11 @@ Stimulus esbuild example -
+

Count:

@@ -13,7 +17,10 @@
-
+

Count: