simple_form-polymorphic_associations 0.0.2 → 0.0.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: 21eb301ad8e23b16a046addbe1317cd2186e56f3bfe84a55efc776aea4a80a53
4
- data.tar.gz: 7dcd29e3e8f196de9b864e7078aa4c5b54c4cb33a84caa8ce25cd85936924bba
3
+ metadata.gz: a66629243386a0ec87cbebee5cc282a84369ce2c35782c9f250d0e6f3d8b870f
4
+ data.tar.gz: f441759360c45c16677e9387c7787676b7986a5cd50f372b9437c57b0867d8f4
5
5
  SHA512:
6
- metadata.gz: 4ba11da6f2849eb955a1a4c6d4bcc44c32f277af6f0c839462e4f4d5e2436c8089a728c02cc41123b3eeaf3ebddf288a61fd2bd40763ea2bdebcc3aa6e803837
7
- data.tar.gz: ff11030145dd42a9708eac2ebe875873c1a50254d8adfd07c009cb0406c2ff30b0ceb28d931f297263ef7d24b30b779085986a2b1a18f9de7f5530096f42f843
6
+ metadata.gz: c857cd4b2b97e18dc5fcc35308931798ed918de3d2358e72b58cd493474c963c10ace1c28f26bdbcfab97b25e3a50fd108b7114241187557332eb6e54487feaa
7
+ data.tar.gz: 179263afafb4328101147694ee8c948b2203fb6cb70ad6b6cd84f36fcec2dba3e70687fd5e7eac05340be2a8a45c9f484c3f694466136643ff00a98690043497
@@ -46,13 +46,16 @@ class PolymorphicAssociationInput < SimpleForm::Inputs::Base
46
46
  def input(wrapper_options = nil)
47
47
  ActiveSupport::SafeBuffer.new.tap do |o|
48
48
  collection = options[:classes].keys.collect { |c| [c.model_name.human, c] }
49
- label_method = :to_s
50
- value_method = :to_s
49
+ instance_label_method = options.delete(:instance_label_method) || :to_s
51
50
  o << @builder.select("#{attribute_name}_type", collection, { include_blank: true }, { class: 'form-control select required polymorphic-association-class-select' })
52
51
  options[:classes].each do |klass, url|
53
52
  o << "<a class=\"polymorphic-association-autocomplete-link\" data-class=\"#{klass}\" href=\"#{url}\" ></a>".html_safe
54
53
  end
55
- o << @builder.select("#{attribute_name}_id", [], {}, { class: 'form-control select required polymorphic-association-resource-select' })
54
+ id_select_collection = []
55
+ if selected_record = object.send(attribute_name).presence
56
+ id_select_collection << [selected_record.send(instance_label_method), selected_record.id]
57
+ end
58
+ o << @builder.select("#{attribute_name}_id", id_select_collection, {}, { class: 'form-control select required polymorphic-association-resource-select' })
56
59
  end
57
60
  end
58
61
  end
@@ -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(user.send(label_method))
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleFormPolymorphicAssociations
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.4"
5
5
  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.2
4
+ version: 0.0.4
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-07 00:00:00.000000000 Z
11
+ date: 2023-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form