rs-activeadmin-searchable_select 4.0.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 +7 -0
- data/.actrc +20 -0
- data/.claude/commands/fix-tests.md +203 -0
- data/.github/workflows/ci.yml +170 -0
- data/.github/workflows/npm-publish.yml +47 -0
- data/.gitignore +27 -0
- data/.npmignore +58 -0
- data/.rspec +2 -0
- data/.rubocop.yml +67 -0
- data/.yardopts +2 -0
- data/AGENTS.md +39 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +24 -0
- data/CLAUDE.md +104 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +366 -0
- data/LICENSE.txt +25 -0
- data/README.md +439 -0
- data/Rakefile +4 -0
- data/bin/rspec +17 -0
- data/config/database.yml +16 -0
- data/config.ru +28 -0
- data/docs/activeadmin-4-detailed-reference.md +932 -0
- data/docs/activeadmin-4-gem-migration-guide.md +313 -0
- data/docs/combustion.md +213 -0
- data/docs/for-next-session.md +199 -0
- data/docs/guide-update-your-app.md +213 -0
- data/docs/propshaft-readme.md +121 -0
- data/docs/propshaft-upgrade.md +267 -0
- data/docs/rails-7-asset-pipeline.md +279 -0
- data/docs/setup-activeadmin-app.md +552 -0
- data/docs/setup-activeadmin-gem.md +535 -0
- data/docs/upload-system.md +225 -0
- data/gemfiles/rails_7.x_active_admin_4.x.gemfile +11 -0
- data/gemfiles/rails_7.x_active_admin_4.x.gemfile.lock +371 -0
- data/gemfiles/rails_8.x_active_admin_4.x.gemfile +11 -0
- data/gemfiles/rails_8.x_active_admin_4.x.gemfile.lock +366 -0
- data/lefthook.yml +17 -0
- data/lib/activeadmin/inputs/filters/searchable_select_input.rb +13 -0
- data/lib/activeadmin/inputs/searchable_select_input.rb +11 -0
- data/lib/activeadmin/searchable_select/engine.rb +17 -0
- data/lib/activeadmin/searchable_select/option_collection.rb +119 -0
- data/lib/activeadmin/searchable_select/resource_dsl_extension.rb +56 -0
- data/lib/activeadmin/searchable_select/resource_extension.rb +10 -0
- data/lib/activeadmin/searchable_select/select_input_extension.rb +159 -0
- data/lib/activeadmin/searchable_select/version.rb +5 -0
- data/lib/activeadmin/searchable_select.rb +20 -0
- data/lib/activeadmin-searchable_select.rb +4 -0
- data/lib/generators/active_admin/searchable_select/install/install_generator.rb +217 -0
- data/package-lock.json +18 -0
- data/package.json +45 -0
- data/rs-activeadmin-searchable_select.gemspec +38 -0
- data/sonar-project.properties +25 -0
- data/spec/features/ajax_params_spec.rb +31 -0
- data/spec/features/end_to_end_spec.rb +227 -0
- data/spec/features/filter_input_spec.rb +137 -0
- data/spec/features/form_input_spec.rb +122 -0
- data/spec/features/inline_ajax_setting_spec.rb +26 -0
- data/spec/features/input_errors_spec.rb +76 -0
- data/spec/features/input_html_options_spec.rb +30 -0
- data/spec/features/options_dsl_spec.rb +220 -0
- data/spec/features/production_build_spec.rb +108 -0
- data/spec/internal/app/admin/categories.rb +26 -0
- data/spec/internal/app/admin/dashboard.rb +29 -0
- data/spec/internal/app/admin/option_types.rb +19 -0
- data/spec/internal/app/admin/option_values.rb +30 -0
- data/spec/internal/app/admin/posts.rb +27 -0
- data/spec/internal/app/admin/products.rb +22 -0
- data/spec/internal/app/admin/rgb_colors.rb +25 -0
- data/spec/internal/app/admin/tag_names.rb +21 -0
- data/spec/internal/app/admin/test_ajax_params_category.rb +10 -0
- data/spec/internal/app/admin/test_ajax_params_post.rb +20 -0
- data/spec/internal/app/admin/test_form_post_class.rb +7 -0
- data/spec/internal/app/admin/test_form_post_custom.rb +11 -0
- data/spec/internal/app/admin/test_form_post_resource.rb +11 -0
- data/spec/internal/app/admin/test_form_post_resource_custom.rb +12 -0
- data/spec/internal/app/admin/test_inline_ajax_post.rb +9 -0
- data/spec/internal/app/admin/test_input_html_post.rb +11 -0
- data/spec/internal/app/admin/test_posts_display_text.rb +9 -0
- data/spec/internal/app/admin/test_posts_filter.rb +9 -0
- data/spec/internal/app/admin/test_posts_named.rb +9 -0
- data/spec/internal/app/admin/test_posts_pagination.rb +9 -0
- data/spec/internal/app/admin/test_posts_payload_lambda.rb +11 -0
- data/spec/internal/app/admin/test_posts_payload_proc.rb +9 -0
- data/spec/internal/app/admin/test_posts_scope_lambda.rb +8 -0
- data/spec/internal/app/admin/test_posts_scope_params.rb +8 -0
- data/spec/internal/app/admin/test_posts_scope_user.rb +8 -0
- data/spec/internal/app/admin/test_posts_text_attr.rb +5 -0
- data/spec/internal/app/admin/users.rb +23 -0
- data/spec/internal/app/admin/variants.rb +31 -0
- data/spec/internal/app/assets/config/manifest.js +1 -0
- data/spec/internal/app/assets/javascripts/active_admin.js +2 -0
- data/spec/internal/app/assets/javascripts/searchable_select_test.js +2 -0
- data/spec/internal/app/controllers/application_controller.rb +5 -0
- data/spec/internal/app/css/active_admin_source.css +81 -0
- data/spec/internal/app/js/active_admin.js +17 -0
- data/spec/internal/app/models/article.rb +12 -0
- data/spec/internal/app/models/category.rb +12 -0
- data/spec/internal/app/models/internal/tag_name.rb +14 -0
- data/spec/internal/app/models/internal_tag_name.rb +11 -0
- data/spec/internal/app/models/option_type.rb +12 -0
- data/spec/internal/app/models/option_value.rb +4 -0
- data/spec/internal/app/models/post.rb +15 -0
- data/spec/internal/app/models/product.rb +12 -0
- data/spec/internal/app/models/rgb_color.rb +16 -0
- data/spec/internal/app/models/user.rb +12 -0
- data/spec/internal/app/models/variant.rb +12 -0
- data/spec/internal/build_activeadmin_css.js +115 -0
- data/spec/internal/config/database.yml +7 -0
- data/spec/internal/config/environment.rb +48 -0
- data/spec/internal/config/initializers/active_admin.rb +53 -0
- data/spec/internal/config/initializers/assets.rb +9 -0
- data/spec/internal/config/initializers/searchable_select.rb +6 -0
- data/spec/internal/config/routes.rb +4 -0
- data/spec/internal/config.ru +4 -0
- data/spec/internal/db/schema.rb +63 -0
- data/spec/internal/db/seeds.rb +88 -0
- data/spec/internal/esbuild.config.js +30 -0
- data/spec/internal/inject-jquery.js +4 -0
- data/spec/internal/log/.gitignore +1 -0
- data/spec/internal/package/LICENSE.txt +25 -0
- data/spec/internal/package/README.md +439 -0
- data/spec/internal/package/package.json +45 -0
- data/spec/internal/package/src/index.js +1 -0
- data/spec/internal/package/src/searchable_select/init.js +1 -0
- data/spec/internal/package/src/searchable_select.css +1 -0
- data/spec/internal/package/src/searchable_select.scss +1 -0
- data/spec/internal/package-lock.json +1385 -0
- data/spec/internal/package.json +26 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/internal/spec/internal/app/css/active_admin_source.css +38 -0
- data/spec/internal/spec/internal/log/test.log +0 -0
- data/spec/internal/tailwind-active_admin.config.js +53 -0
- data/spec/rails_helper.rb +86 -0
- data/spec/spec_helper.rb +137 -0
- data/spec/support/active_admin_helpers.rb +17 -0
- data/spec/support/capybara.rb +8 -0
- data/spec/support/models.rb +88 -0
- data/spec/support/pluck_polyfill.rb +12 -0
- data/spec/support/reset_settings.rb +5 -0
- data/src/index.js +77 -0
- data/src/searchable_select/init.js +58 -0
- data/src/searchable_select.css +5 -0
- data/src/searchable_select.css.map +1 -0
- metadata +405 -0
data/README.md
ADDED
@@ -0,0 +1,439 @@
|
|
1
|
+
# ActiveAdmin Searchable Select (RocketSensei Fork)
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/rs-activeadmin-searchable_select)
|
4
|
+
[](https://badge.fury.io/js/@rocket-sensei%2Factiveadmin-searchable_select)
|
5
|
+
[](https://www.npmjs.com/package/@rocket-sensei/activeadmin-searchable_select)
|
6
|
+
[](https://github.com/glebtv/activeadmin-searchable_select/actions)
|
7
|
+
|
8
|
+
Searchable select boxes (via [Select2](https://select2.org/)) for
|
9
|
+
ActiveAdmin forms and filters. Extends the ActiveAdmin resource DSL to
|
10
|
+
allow defining JSON endpoints to fetch options from asynchronously.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add `rs-activeadmin-searchable_select` to your Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'rs-activeadmin-searchable_select'
|
18
|
+
```
|
19
|
+
|
20
|
+
### ActiveAdmin 4.x with Rails 8 (esbuild/importmap/Propshaft)
|
21
|
+
|
22
|
+
This fork is optimized for ActiveAdmin 4.x with Rails 8, supporting modern JavaScript bundlers and Propshaft. If you encounter "select2 is not a function" errors in production, see the [complete setup guide](docs/guide-update-your-app.md).
|
23
|
+
|
24
|
+
#### Quick Install with Generator
|
25
|
+
|
26
|
+
```bash
|
27
|
+
# For esbuild (recommended)
|
28
|
+
rails generate active_admin:searchable_select:install
|
29
|
+
|
30
|
+
# For importmap
|
31
|
+
rails generate active_admin:searchable_select:install --bundler=importmap
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Manual Setup for esbuild
|
35
|
+
|
36
|
+
1. Install npm packages:
|
37
|
+
```bash
|
38
|
+
npm install @rocket-sensei/activeadmin-searchable_select jquery select2
|
39
|
+
```
|
40
|
+
|
41
|
+
2. In `app/javascript/active_admin.js`:
|
42
|
+
```javascript
|
43
|
+
import "@activeadmin/activeadmin";
|
44
|
+
import $ from 'jquery';
|
45
|
+
import select2 from 'select2';
|
46
|
+
|
47
|
+
// Critical: Initialize select2 on jQuery (fixes production builds)
|
48
|
+
select2($);
|
49
|
+
window.$ = window.jQuery = $;
|
50
|
+
|
51
|
+
import '@rocket-sensei/activeadmin-searchable_select';
|
52
|
+
```
|
53
|
+
|
54
|
+
3. Add Select2 CSS to your ActiveAdmin stylesheet:
|
55
|
+
```css
|
56
|
+
@import url('https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css');
|
57
|
+
```
|
58
|
+
|
59
|
+
### ActiveAdmin 3.x and older
|
60
|
+
|
61
|
+
##### Using assets via Sprockets
|
62
|
+
Import stylesheets and require javascripts:
|
63
|
+
|
64
|
+
```scss
|
65
|
+
// active_admin.css.scss
|
66
|
+
@import "active_admin/searchable_select";
|
67
|
+
```
|
68
|
+
|
69
|
+
```coffee
|
70
|
+
// active_admin.js
|
71
|
+
//= require active_admin/searchable_select
|
72
|
+
```
|
73
|
+
|
74
|
+
##### Using assets via Webpacker
|
75
|
+
|
76
|
+
Add to `package.json`:
|
77
|
+
```json
|
78
|
+
"dependencies": {
|
79
|
+
"@rocket-sensei/activeadmin-searchable_select": "^4.0.0"
|
80
|
+
}
|
81
|
+
```
|
82
|
+
|
83
|
+
In `app/javascript/packs/active_admin.js`:
|
84
|
+
```javascript
|
85
|
+
import '@rocket-sensei/activeadmin-searchable_select';
|
86
|
+
```
|
87
|
+
|
88
|
+
In `app/javascript/stylesheets/active_admin.scss`:
|
89
|
+
```css
|
90
|
+
@import '@rocket-sensei/activeadmin-searchable_select';
|
91
|
+
```
|
92
|
+
|
93
|
+
## Usage
|
94
|
+
|
95
|
+
### Making Select Boxes Searchable
|
96
|
+
|
97
|
+
To add search functionality to a select box, use the
|
98
|
+
`:searchable_select` input type:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
ActiveAdmin.register Product do
|
102
|
+
form do |f|
|
103
|
+
f.input(:category, as: :searchable_select)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
This also works for filters:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
ActiveAdmin.register Product do
|
112
|
+
filter(:category, as: :searchable_select)
|
113
|
+
end
|
114
|
+
```
|
115
|
+
|
116
|
+
By default, you can only select one at a time for a filter. You can
|
117
|
+
specify a multi-select with:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
ActiveAdmin.register Product do
|
121
|
+
filter(:category, as: :searchable_select, multiple: true)
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
### Fetching Options via Ajax
|
126
|
+
|
127
|
+
For large collections, rendering the whole set of options can be to
|
128
|
+
expensive. Use the `ajax` option to fetch a set of matching options
|
129
|
+
once the user begins to type:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
|
133
|
+
ActiveAdmin.register Product do
|
134
|
+
filter(:category,
|
135
|
+
as: :searchable_select,
|
136
|
+
ajax: true)
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
140
|
+
If the input attribute corresponds to an ActiveAdmin resource, it is
|
141
|
+
expected to provide the JSON endpoint that provides the options. Use
|
142
|
+
the `searchable_select_options` method to define the required
|
143
|
+
collection action:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
ActiveAdmin.register Category do
|
147
|
+
searchable_select_options(scope: Category.all,
|
148
|
+
text_attribute: :name)
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
By default, `scope` needs to be a Ransack enabled ActiveRecord
|
153
|
+
collection proxy determining which options are available. The
|
154
|
+
attribute given by `text_attribute` will be used to get a display name
|
155
|
+
for each record. Via Ransack, it is also used to filter by search
|
156
|
+
term. Limiting result set size is handled automatically.
|
157
|
+
|
158
|
+
You can customize the display text:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
ActiveAdmin.register Category do
|
162
|
+
searchable_select_options(scope: Category.all,
|
163
|
+
text_attribute: :name,
|
164
|
+
display_text: ->(record) { "Category: #{record.name}" } )
|
165
|
+
end
|
166
|
+
```
|
167
|
+
|
168
|
+
Note that `text_attribute` is still required to perform filtering via
|
169
|
+
Ransack. You can pass the `filter` option, to specify your own
|
170
|
+
filtering strategy:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
ActiveAdmin.register Category do
|
174
|
+
searchable_select_options(scope: Category.all,
|
175
|
+
text_attribute: :name,
|
176
|
+
filter: lambda |term, scope|
|
177
|
+
scope.ransack(name_cont_all: term.split(' ')).result
|
178
|
+
end)
|
179
|
+
end
|
180
|
+
```
|
181
|
+
|
182
|
+
`scope` can also be a lambda which is evaluated in the context of the
|
183
|
+
collection action defined by the helper:
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
ActiveAdmin.register Category do
|
187
|
+
searchable_select_options(scope: -> { Category.allowed_for(current_user) },
|
188
|
+
text_attribute: :name)
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
If the input attribute is set on the form's object, ajax based
|
193
|
+
searchable selects will automatically render a single option to ensure
|
194
|
+
the selected item is displayed correctly even before options have been
|
195
|
+
loaded asynchronously.
|
196
|
+
|
197
|
+
#### Specifying the Options Endpoint Resource
|
198
|
+
|
199
|
+
If the resource that provides the options endpoint cannot be guessed
|
200
|
+
based on the input attribute name, you can pass an object with a
|
201
|
+
`resource` key as `ajax` option:
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
ActiveAdmin.register Product do
|
205
|
+
form do |f|
|
206
|
+
f.input(:additional_category,
|
207
|
+
as: :searchable_select,
|
208
|
+
ajax: { resource: Category })
|
209
|
+
end
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
#### Multiple Options Endpoints per Resource
|
214
|
+
|
215
|
+
A single ActiveAdmin resource can define multiple options endpoints:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
ActiveAdmin.register Category do
|
219
|
+
searchable_select_options(name: :favorites,
|
220
|
+
scope: Category.favorites,
|
221
|
+
text_attribute: :name)
|
222
|
+
|
223
|
+
searchable_select_options(name: :recent,
|
224
|
+
scope: Category.recent,
|
225
|
+
text_attribute: :name)
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
229
|
+
To specify which collection to use, pass an object with a
|
230
|
+
`collection_name` key as `ajax` option:
|
231
|
+
|
232
|
+
```ruby
|
233
|
+
ActiveAdmin.register Product do
|
234
|
+
form do |f|
|
235
|
+
f.input(:category,
|
236
|
+
as: :searchable_select,
|
237
|
+
ajax: { collection_name: :favorites })
|
238
|
+
end
|
239
|
+
end
|
240
|
+
```
|
241
|
+
|
242
|
+
#### Querying Multiple Attributes
|
243
|
+
|
244
|
+
ActiveAdmin Searchable Select querying is performed by Ransack. As such, you can
|
245
|
+
build your query in a way that it can query multiple attributes at once.
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
ActiveAdmin.register User do
|
249
|
+
searchable_select_options(scope: User.all,
|
250
|
+
text_attribute: :username,
|
251
|
+
filter: lambda do |term, scope|
|
252
|
+
scope.ransack(email_or_username_cont: term).result
|
253
|
+
end)
|
254
|
+
end
|
255
|
+
```
|
256
|
+
|
257
|
+
In this example, the `all` scope will query `email OR username`.
|
258
|
+
|
259
|
+
You can add the additional payload as dsl option:
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
ActiveAdmin.register Category do
|
263
|
+
searchable_select_options(scope: Category.all,
|
264
|
+
text_attribute: :name,
|
265
|
+
additional_payload: ->(record) { { foo: record.bar } } )
|
266
|
+
end
|
267
|
+
```
|
268
|
+
|
269
|
+
response example which uses additional_payload:
|
270
|
+
|
271
|
+
```json
|
272
|
+
{
|
273
|
+
"results": [{ "id": "1", "text": "Bicycles", "foo": "Bar" }],
|
274
|
+
"pagination": { "more": "false" }
|
275
|
+
}
|
276
|
+
```
|
277
|
+
|
278
|
+
#### Passing Parameters
|
279
|
+
|
280
|
+
You can pass additional parameters to the options endpoint:
|
281
|
+
|
282
|
+
```ruby
|
283
|
+
ActiveAdmin.register Product do
|
284
|
+
form do |f|
|
285
|
+
f.input(:category,
|
286
|
+
as: :searchable_select,
|
287
|
+
ajax: {
|
288
|
+
params: {
|
289
|
+
some: 'value'
|
290
|
+
}
|
291
|
+
})
|
292
|
+
end
|
293
|
+
end
|
294
|
+
```
|
295
|
+
|
296
|
+
The lambda passed as `scope` can receive those parameters as first
|
297
|
+
argument:
|
298
|
+
|
299
|
+
```ruby
|
300
|
+
ActiveAdmin.register Category do
|
301
|
+
searchable_select_options(scope: lambda do |params|
|
302
|
+
Category.find_all_by_some(params[:some])
|
303
|
+
end,
|
304
|
+
text_attribute: :name)
|
305
|
+
end
|
306
|
+
```
|
307
|
+
|
308
|
+
#### Path options for nested resources
|
309
|
+
|
310
|
+
Example for the following setup:
|
311
|
+
|
312
|
+
```ruby
|
313
|
+
# Models
|
314
|
+
class OptionType < ActiveRecord::Base; end
|
315
|
+
|
316
|
+
class OptionValue < ActiveRecord::Base
|
317
|
+
belongs_to :option_type
|
318
|
+
end
|
319
|
+
|
320
|
+
class Product < ActiveRecord::Base
|
321
|
+
belongs_to :option_type
|
322
|
+
has_many :variants
|
323
|
+
end
|
324
|
+
|
325
|
+
class Variant < ActiveRecord::Base
|
326
|
+
belongs_to :product
|
327
|
+
belongs_to :option_value
|
328
|
+
end
|
329
|
+
|
330
|
+
# ActiveAdmin
|
331
|
+
ActiveAdmin.register(OptionType)
|
332
|
+
|
333
|
+
ActiveAdmin.register(Product)
|
334
|
+
|
335
|
+
ActiveAdmin.register(OptionValue) do
|
336
|
+
belongs_to :option_type
|
337
|
+
searchable_select_options(scope: lambda do |params|
|
338
|
+
OptionValue.where(
|
339
|
+
option_type_id: params[:option_type_id]
|
340
|
+
)
|
341
|
+
end,
|
342
|
+
text_attribute: :value)
|
343
|
+
end
|
344
|
+
```
|
345
|
+
|
346
|
+
It is possible to pass path parameters for correctly generating URLs for nested resources fetching via `path_params`
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
ActiveAdmin.register(Variant) do
|
350
|
+
belongs_to :product
|
351
|
+
|
352
|
+
form do |f|
|
353
|
+
...
|
354
|
+
f.input(:option_value,
|
355
|
+
as: :searchable_select,
|
356
|
+
ajax: {
|
357
|
+
resource: OptionValue,
|
358
|
+
path_params: {
|
359
|
+
option_type_id: f.object.product.option_type_id
|
360
|
+
}
|
361
|
+
})
|
362
|
+
...
|
363
|
+
end
|
364
|
+
end
|
365
|
+
```
|
366
|
+
|
367
|
+
This will generate the path for fetching as `all_options_admin_option_type_option_values(option_type_id: f.object.product.option_type_id)` (e.g. `/admin/option_types/2/option_values/all_options`)
|
368
|
+
|
369
|
+
#### Inlining Ajax Options in Feature Tests
|
370
|
+
|
371
|
+
When writing UI driven feature specs (i.e. with Capybara),
|
372
|
+
asynchronous loading of select options can increase test
|
373
|
+
complexity. `activeadmin-searchable_select` provides an option to
|
374
|
+
render all available options just like a normal select input while
|
375
|
+
still exercsing the same code paths including `scope` and
|
376
|
+
`text_attribute` handling.
|
377
|
+
|
378
|
+
For example with RSpec/Capybara, simply set `inline_ajax_options` true
|
379
|
+
for feature specs:
|
380
|
+
|
381
|
+
```ruby
|
382
|
+
RSpec.configure do |config|
|
383
|
+
config.before(:each) do |example|
|
384
|
+
ActiveAdmin::SearchableSelect.inline_ajax_options = (example.metadata[:type] == :feature)
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
```
|
389
|
+
|
390
|
+
### Passing options to Select2
|
391
|
+
|
392
|
+
It is possible to pass and define configuration options to Select2
|
393
|
+
via `data-attributes` using nested (subkey) options.
|
394
|
+
|
395
|
+
Attributes need to be added to the `input_html` option in the form input.
|
396
|
+
For example you can tell Select2 how long to wait after a user
|
397
|
+
has stopped typing before sending the request:
|
398
|
+
|
399
|
+
```ruby
|
400
|
+
...
|
401
|
+
f.input(:category,
|
402
|
+
as: :searchable_select,
|
403
|
+
ajax: true,
|
404
|
+
input_html: {
|
405
|
+
data: {
|
406
|
+
'ajax--delay' => 500
|
407
|
+
}
|
408
|
+
})
|
409
|
+
...
|
410
|
+
```
|
411
|
+
|
412
|
+
|
413
|
+
## Development
|
414
|
+
|
415
|
+
To run the tests install bundled gems and invoke RSpec:
|
416
|
+
|
417
|
+
```
|
418
|
+
$ bundle
|
419
|
+
$ bundle exec rspec
|
420
|
+
```
|
421
|
+
|
422
|
+
The test suite can be run against different versions of Rails and
|
423
|
+
Active Admin (see `Appraisals` file):
|
424
|
+
|
425
|
+
```
|
426
|
+
$ appraisal install
|
427
|
+
$ appraisal rspec
|
428
|
+
```
|
429
|
+
|
430
|
+
Please make sure changes conform with the styleguide:
|
431
|
+
|
432
|
+
```
|
433
|
+
$ bundle exec rubocop
|
434
|
+
```
|
435
|
+
|
436
|
+
## Acknowledgements
|
437
|
+
|
438
|
+
Based on
|
439
|
+
[mfairburn/activeadmin-select2](https://github.com/mfairburn/activeadmin-select2).
|
data/Rakefile
ADDED
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/config/database.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
default: &default
|
2
|
+
adapter: sqlite3
|
3
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
4
|
+
timeout: 5000
|
5
|
+
|
6
|
+
development:
|
7
|
+
<<: *default
|
8
|
+
database: db/development.sqlite3
|
9
|
+
|
10
|
+
test:
|
11
|
+
<<: *default
|
12
|
+
database: db/test.sqlite3
|
13
|
+
|
14
|
+
production:
|
15
|
+
<<: *default
|
16
|
+
database: db/production.sqlite3
|
data/config.ru
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
# Don't auto-require gems - we need to control loading order
|
7
|
+
Bundler.setup(:default, :development)
|
8
|
+
|
9
|
+
# Load Rails and combustion first
|
10
|
+
require 'combustion'
|
11
|
+
|
12
|
+
# Require propshaft explicitly before initializing
|
13
|
+
require 'propshaft' if defined?(Propshaft) || Bundler.load.specs.find { |s| s.name == 'propshaft' }
|
14
|
+
|
15
|
+
# Initialize Combustion with the Rails components we need
|
16
|
+
Combustion.initialize! :active_record, :action_controller, :action_view, :propshaft do
|
17
|
+
config.load_defaults Rails::VERSION::STRING.to_f if Rails::VERSION::MAJOR >= 7
|
18
|
+
end
|
19
|
+
|
20
|
+
# Now that Rails is initialized, we can load ActiveAdmin and its dependencies
|
21
|
+
require 'active_admin'
|
22
|
+
require 'activeadmin/searchable_select'
|
23
|
+
|
24
|
+
# Ensure Formtastic input is loaded
|
25
|
+
require 'activeadmin/inputs/searchable_select_input'
|
26
|
+
require 'activeadmin/inputs/filters/searchable_select_input'
|
27
|
+
|
28
|
+
run Combustion::Application
|