bullet_train 1.6.3 → 1.6.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c76cb66088988d0ed0e9e1b2f444f4377bd8ba8531d2ec6f9d00b7374e8d5f0f
4
- data.tar.gz: 29dfa7afdad1612cb2ac44b264d408877dea791e34f670f34b2b2cc0c73b5384
3
+ metadata.gz: 6cf9564d4d63992dbe9df4f6de5f4ab36779ca94917f109266bfd6073c6dc22d
4
+ data.tar.gz: 81076fc1023dfc4ea68780b458bcd963cd8206745a8864a254df363e5b87cbe5
5
5
  SHA512:
6
- metadata.gz: 5b2e8240126515b5b6abf0015efa63ac4c320173c4c97508843627487434aaa87a04fe5cf2a691c8e7059cd6458334ab201911b7384ddb86e3abee01df680755
7
- data.tar.gz: 23e1a5035a6b5c0d8d52af7ab529ecd9b7fbae774e34fb6655c3f72056f17d16492b1bfa2ede9e270280fa516bb8b7e11fd20931a29ef8ff081f3f103fa6eabb
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).
@@ -1,3 +1,3 @@
1
1
  module BulletTrain
2
- VERSION = "1.6.3"
2
+ VERSION = "1.6.5"
3
3
  end
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.3
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-13 00:00:00.000000000 Z
11
+ date: 2023-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard