bullet_train 1.6.3 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/field-partials/super-select.md +29 -3
- data/lib/bullet_train/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cf9564d4d63992dbe9df4f6de5f4ab36779ca94917f109266bfd6073c6dc22d
|
4
|
+
data.tar.gz: 81076fc1023dfc4ea68780b458bcd963cd8206745a8864a254df363e5b87cbe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aa704f739f7d20d8da157aaafa6dea19e5c0900109b958c17de77198b135ba381fb85df30413fb63dd0c655da5cd092ced876c00470bf6ac6c5c7fc9f2046aa
|
7
|
+
data.tar.gz: 6ade1feff8b5990362076b9dc871ef760571acb4852467ef945792f2f87fa27d75168a8df25ec6d9bb858af2a9c2f85d1a09ad956c260f886dc1d7bed347a250
|
@@ -71,6 +71,32 @@ Here is an example allowing a new option to be entered by the user:
|
|
71
71
|
</code></pre>
|
72
72
|
|
73
73
|
Note: this will set the option `value` (which will be submitted to the server) to the entered text.
|
74
|
+
|
75
|
+
To handle the new entry's text on the server, use `ensure_backing_models_on`.
|
76
|
+
|
77
|
+
`ensure_backing_models_on` validates an `id:` or multiple `ids:` against a passed Active Record relation, and yields for each missing id so you can create backing models. Like this:
|
78
|
+
|
79
|
+
```rb
|
80
|
+
if strong_params[:category_id]
|
81
|
+
strong_params[:category_id] = ensure_backing_models_on(current_team.categories, id: strong_params[:category_id]) do |scope, id|
|
82
|
+
scope.find_or_create_by(name: id)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
In case our form had `multiple: true`, we could have used `ids:` instead:
|
88
|
+
|
89
|
+
```rb
|
90
|
+
if strong_params[:category_ids]
|
91
|
+
strong_params[:category_ids] = ensure_backing_models_on(current_team.categories, ids: strong_params[:category_ids]) do |scope, id|
|
92
|
+
scope.find_or_create_by(name: id)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
Note, if you need to constrain the collection further you could pass any extra scope, e.g. `current_team.categories.not_archived`.
|
98
|
+
|
99
|
+
|
74
100
|
## Events
|
75
101
|
|
76
102
|
All events dispatched from the `super_select` partial are [Select2's jQuery events][select2_events] re-dispatched as native DOM events with the following caveats:
|
@@ -115,11 +141,11 @@ import { Controller } from "stimulus"
|
|
115
141
|
|
116
142
|
export default class extends Controller {
|
117
143
|
static targets = [ "dependentField" ]
|
118
|
-
|
144
|
+
|
119
145
|
updateDependentFields(event) {
|
120
146
|
const originalSelect2Event = event.detail.event
|
121
147
|
console.log(`catching event ${event.type}`, originalSelect2Event)
|
122
|
-
|
148
|
+
|
123
149
|
this.dependentFieldTargets.forEach((dependentField) => {
|
124
150
|
// update dependentField based on value found in originalSelect2Event.target.value
|
125
151
|
})
|
@@ -152,4 +178,4 @@ If you'd like to:
|
|
152
178
|
* modify other fields based on the value of your `super_select`, or
|
153
179
|
* modify your `super_select` based on the value of other fields
|
154
180
|
|
155
|
-
See [Dynamic Forms and Dependent Fields](/docs/field-partials/dynamic-forms-dependent-fields.md).
|
181
|
+
See [Dynamic Forms and Dependent Fields](/docs/field-partials/dynamic-forms-dependent-fields.md).
|
data/lib/bullet_train/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bullet_train
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Culver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: standard
|