bullet_train 1.6.3 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c76cb66088988d0ed0e9e1b2f444f4377bd8ba8531d2ec6f9d00b7374e8d5f0f
4
- data.tar.gz: 29dfa7afdad1612cb2ac44b264d408877dea791e34f670f34b2b2cc0c73b5384
3
+ metadata.gz: 0f600ed43bf526b425a8401848ec54cb2560cb7fa0e45fe2e0b6a2976949e975
4
+ data.tar.gz: d0833d3c1ce80839f416fec71d4b38a2099942cc3cd01e5e2712fbb2f4cf0501
5
5
  SHA512:
6
- metadata.gz: 5b2e8240126515b5b6abf0015efa63ac4c320173c4c97508843627487434aaa87a04fe5cf2a691c8e7059cd6458334ab201911b7384ddb86e3abee01df680755
7
- data.tar.gz: 23e1a5035a6b5c0d8d52af7ab529ecd9b7fbae774e34fb6655c3f72056f17d16492b1bfa2ede9e270280fa516bb8b7e11fd20931a29ef8ff081f3f103fa6eabb
6
+ metadata.gz: 77246baefaeb8fce78e10c6202410b5952589edbc6391777ed3b671db4b3e89b622684273c49440cac103b159b733a1cd5b08445a57fc95e6a9f86722d5d106a
7
+ data.tar.gz: c98756ba46b9d2349d687a79e28930cc8aba287dc65d4cedc093bc4a21bf3ebea5f160dd8b2df296a55a6d1dc081ebe1da4340cc850b6fbe8f93e6ea31660241
@@ -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.4"
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.4
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-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard