diff --git a/app/static/js/core/examples.js b/app/static/js/core/examples.js index d454e990..07d6c3e0 100644 --- a/app/static/js/core/examples.js +++ b/app/static/js/core/examples.js @@ -1,18 +1,17 @@ const visibility = { - open: false, + isOpen: false, label: "Show", - - toggle(event) { - this.open = !this.open; - this.label = this.open ? "Hide" : "Show"; + toggle() { + this.isOpen = !this.isOpen; + this.label = this.isOpen ? "Hide" : "Show"; }, }; registerAlpineComponent("visibility", visibility); const slider = { percentage: 50, - update(event) { - this.percentage = event.target.value; + update() { + this.percentage = this.$el.value; }, }; registerAlpineComponent("slider", slider); @@ -21,8 +20,11 @@ const nameForm = { firstName: "", lastName: "", fullName: "(empty)", - handleInput(event) { - this[event.target.name] = event.target.value; + focus() { + this.$el.focus(); + }, + handleInput() { + this[this.$el.name] = this.$el.value; const fullName = `${this.firstName} ${this.lastName}`; this.fullName = !this.firstName && !this.lastName ? "(empty)" : fullName; }, diff --git a/app/templates/base.html b/app/templates/base.html index 8214becf..16ef67eb 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -32,7 +32,7 @@ {# Alpine.js CSP boilerplate (must come before custom JS, which must come before alpinejs library) #} {% if settings.enable_alpinejs_csp %} - + {% endif %} {# JS Config #} diff --git a/app/templates/examples/alpine_form/README.md b/app/templates/examples/alpine/README.md similarity index 66% rename from app/templates/examples/alpine_form/README.md rename to app/templates/examples/alpine/README.md index 9ea14ddb..e0c69b96 100644 --- a/app/templates/examples/alpine_form/README.md +++ b/app/templates/examples/alpine/README.md @@ -1,6 +1,6 @@ -# Alpine.js form sample +# Alpine.js sample -When you type in a name in the `First Name` and `Last Name` form fields, Alpine.js will live-update the `Full Name`. +This example demonstrates a few common Alpine.js features. They are explained on the task pane itself. To try it out, replace `app/routers/taskpane.py` with the following code: @@ -16,7 +16,7 @@ router = APIRouter() async def taskpane(request: Request): return TemplateResponse( request=request, - name="examples/alpine_form/taskpane_form.html", + name="examples/alpine/taskpane.html", ) ``` diff --git a/app/templates/examples/alpine_form/taskpane_form.html b/app/templates/examples/alpine/taskpane.html similarity index 82% rename from app/templates/examples/alpine_form/taskpane_form.html rename to app/templates/examples/alpine/taskpane.html index fe042ce6..408c66cb 100644 --- a/app/templates/examples/alpine_form/taskpane_form.html +++ b/app/templates/examples/alpine/taskpane.html @@ -5,8 +5,8 @@
Show and hide an element.
Concatenate the first and last name as you type.
+
+ Concatenates the first and last name as you type. You can activate the First Name input box via the
+ /
keyboard shortcut.
+