turbo_form 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/assets/javascripts/turbo_form.js +8 -1
- data/lib/turbo_form/controller.rb +11 -9
- data/lib/turbo_form/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4cb1af8f341d1112a85f86bc4fe28470e83f867994be6029a32fbd996da03677
|
|
4
|
+
data.tar.gz: 97afa78d913454ea096c0f988ecb85d99f7ebe7027f02f2e19cc40af534b624e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 221fbbcd5e31c6191a208cefb92089f70094ef5709547cdb63984a4bb419342d7109dfe4001135853ee7380537b63d82a8cb2fef64af550d40a1a713dfa93f20
|
|
7
|
+
data.tar.gz: 2e7cd4ecec1194cc7605035e9a51c9dcd1542f3c45410c6497a74221e8ae6a037991650a6d928bdf230097af4cfbc0e7aaf73751326a912f291649b9e22221b4
|
data/README.md
CHANGED
|
@@ -133,9 +133,9 @@ For a `WidgetsController`:
|
|
|
133
133
|
- `new` and `edit` set `@widget`,
|
|
134
134
|
- `widget_params` permits the form's fields — the same method `create` and
|
|
135
135
|
`update` already use, so a trigger assigns nothing a save wouldn't,
|
|
136
|
-
- `new` and `edit`
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
- `new` and `edit` render their own template, implicitly or with `render`
|
|
137
|
+
themselves — `render layout: 'panel'` is fine. The values are assigned just
|
|
138
|
+
before it renders; an action that redirects still redirects.
|
|
139
139
|
|
|
140
140
|
### Switching an STI subclass
|
|
141
141
|
|
|
@@ -26,7 +26,7 @@ class FormRefresh {
|
|
|
26
26
|
async start() {
|
|
27
27
|
this.requestStarted()
|
|
28
28
|
try {
|
|
29
|
-
const response = await Turbo.fetch(this.location, { method: "PATCH", body: new FormData(this.formElement), headers: this.target.headers })
|
|
29
|
+
const response = await Turbo.fetch(this.location, { method: "PATCH", body: new FormData(this.formElement), headers: { ...this.target.headers, "X-CSRF-Token": csrfToken() } })
|
|
30
30
|
|
|
31
31
|
this.target.render(response.status, await response.text())
|
|
32
32
|
} finally {
|
|
@@ -88,6 +88,13 @@ function targetFor(form) {
|
|
|
88
88
|
return frame ? new FrameTarget(frame) : new PageTarget()
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
// The form's own authenticity token is scoped to its action and method when
|
|
92
|
+
// per-form tokens are on, as they are by default, so it can't vouch for this
|
|
93
|
+
// PATCH. The page's token can, as it does for Turbo's own submissions.
|
|
94
|
+
function csrfToken() {
|
|
95
|
+
return document.querySelector('meta[name="csrf-token"]')?.content
|
|
96
|
+
}
|
|
97
|
+
|
|
91
98
|
const triggerSelector = "[data-turbo-form-trigger]"
|
|
92
99
|
|
|
93
100
|
// Shaped like Turbo's observers. One listener per event the page's triggers
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
module TurboForm
|
|
2
2
|
# Included into the host's ApplicationController. A request that
|
|
3
3
|
# TurboForm::Routes marks runs `new` or `edit` as usual, callbacks and all,
|
|
4
|
-
# then assigns the form to what the action built just before
|
|
5
|
-
# render
|
|
4
|
+
# then assigns the form to what the action built just before it renders --
|
|
5
|
+
# implicitly, or with its own `render layout: 'panel'`.
|
|
6
6
|
#
|
|
7
|
-
# Leans on the scaffold's conventions: the action builds `@<resource
|
|
8
|
-
# `<resource>_params` permits the form
|
|
7
|
+
# Leans on the scaffold's conventions: the action builds `@<resource>` and
|
|
8
|
+
# `<resource>_params` permits the form.
|
|
9
9
|
module Controller
|
|
10
|
+
# Public, as Rails' own is. ActionController::Base's public methods are never
|
|
11
|
+
# actions, so this one isn't either.
|
|
12
|
+
def render(...)
|
|
13
|
+
dynamic_form_assignment if dynamic_form?
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
|
|
10
17
|
private
|
|
11
18
|
def process_action(...)
|
|
12
19
|
dynamic_form? ? discarding_writes { super } : super
|
|
13
20
|
end
|
|
14
21
|
|
|
15
|
-
def default_render
|
|
16
|
-
dynamic_form_assignment if dynamic_form?
|
|
17
|
-
super
|
|
18
|
-
end
|
|
19
|
-
|
|
20
22
|
def dynamic_form_assignment
|
|
21
23
|
resource = turbo_form_resource.extend(TurboForm::Resource).dynamic_assign(turbo_form_resource_params)
|
|
22
24
|
instance_variable_set(:"@#{turbo_form_resource_name}", resource)
|
data/lib/turbo_form/version.rb
CHANGED