bullet_train 1.6.3 → 1.6.4
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/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: 0f600ed43bf526b425a8401848ec54cb2560cb7fa0e45fe2e0b6a2976949e975
         | 
| 4 | 
            +
              data.tar.gz: d0833d3c1ce80839f416fec71d4b38a2099942cc3cd01e5e2712fbb2f4cf0501
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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).
         | 
    
        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.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- | 
| 11 | 
            +
            date: 2023-10-16 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: standard
         |