simple_form-polymorphic_associations 0.0.3 → 0.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 +4 -4
- data/app/assets/javascripts/simple_form-polymorphic_associations/application/autocomplete.js.coffee +31 -6
- data/app/assets/javascripts/simple_form-polymorphic_associations.js +1 -1
- data/lib/simple_form-polymorphic_associations/spec_helpers/system.rb +1 -1
- data/lib/simple_form-polymorphic_associations/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0886162b184227281cbda58946bcaebe1b4c9414d4b63f8f27457e786714a293'
|
4
|
+
data.tar.gz: 6498888d3b5c2e4cb0706731a34d395f4523cb675a702258b41fbb5138bdd430
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d34e50a1cfd8ac921abe43a93667bcba3cd744c2742de5b67675a144f15cfe2a6943b4b9fb64a93ee5ee6ad862323a997b2c9340b6b8d6f6e1536bffc1f47a70
|
7
|
+
data.tar.gz: 97932eb80112cb60eb6f98da0a542f09515e3289ee63980ee66e0db5831597095519a0e22f31eebab754eb11221e10b3db2066c0c61ddf98d251e0c669fe95da
|
data/app/assets/javascripts/simple_form-polymorphic_associations/application/autocomplete.js.coffee
CHANGED
@@ -1,7 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
window.SimpleFormPolymorphicAssociations = window.SimpleFormPolymorphicAssociations ? {}
|
2
|
+
|
3
|
+
# When dynamically adding a new polymorphic association, we need to rebind the
|
4
|
+
# autocomplete to the new select2 element. This is done by calling the constructor
|
5
|
+
# on the new element.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# :javascript
|
10
|
+
# var resourceSelect = $("#some-form").find(".polymorphic-association-resource-select")
|
11
|
+
# if (window.SimpleFormPolymorphicAssociations) {
|
12
|
+
# new window.SimpleFormPolymorphicAssociations.Autocomplete(resourceSelect);
|
13
|
+
# } else {
|
14
|
+
# console.error('window.SimpleFormPolymorphicAssociations.Autocomplete is not defined');
|
15
|
+
# }
|
16
|
+
#
|
17
|
+
class SimpleFormPolymorphicAssociations.Autocomplete
|
18
|
+
constructor: (@element) ->
|
19
|
+
@getUrl = @getUrl.bind(this)
|
20
|
+
@element.select2 ajax: @getAjaxOptions()
|
21
|
+
|
22
|
+
getAjaxOptions: ->
|
23
|
+
url: @getUrl
|
24
|
+
dataType: 'json'
|
7
25
|
delay: 500
|
26
|
+
|
27
|
+
getUrl: ->
|
28
|
+
klass = @element.siblings('.polymorphic-association-class-select').first().val()
|
29
|
+
@element.parent().find(".polymorphic-association-autocomplete-link[data-class='#{klass}']").attr('href')
|
30
|
+
|
31
|
+
$ ->
|
32
|
+
new SimpleFormPolymorphicAssociations.Autocomplete($('.polymorphic-association-resource-select'))
|
@@ -1 +1 @@
|
|
1
|
-
//= require simple_form-polymorphic_associations/application
|
1
|
+
//= require simple_form-polymorphic_associations/application
|
@@ -30,7 +30,7 @@ module SimpleFormPolymorphicAssociations
|
|
30
30
|
def polymorphic_select(record, label_method, options)
|
31
31
|
select record.class.model_name.human, from: options[:from].gsub(/_id]$/, "_type]")
|
32
32
|
first(".select2-container", minimum: 1).click
|
33
|
-
find(".select2-search--dropdown input.select2-search__field").send_keys(
|
33
|
+
find(".select2-search--dropdown input.select2-search__field").send_keys(record.send(label_method))
|
34
34
|
sleep(1)
|
35
35
|
find(".select2-search--dropdown input.select2-search__field").send_keys(:enter)
|
36
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form-polymorphic_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_form
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
66
|
+
rubygems_version: 3.4.21
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: Simple Form polymorphic associations.
|