simple_form_autocomplete 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/simple_form/inputs/autocomplete_input.rb +5 -3
- data/lib/simple_form_autocomplete/version.rb +1 -1
- data/simple_form_autocomplete.gemspec +1 -2
- data/spec/simple_form/inputs/autocomplete_input_spec.rb +34 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/support/helpers.rb +1 -0
- metadata +10 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4c06e7ce6d644d80eb4869681d7d48116d40bf1
|
4
|
+
data.tar.gz: 1fe03e4fcb1bb0055509914a3cce8f4cceac1514
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d8ce275ce3c1f571911317f3db63d6137e56aea3d1cbb284d2335ae5c0db37af29eca6ad284eaf94bc1f8601351b8bab8b2197ce0985526f288bc5c6e92a26
|
7
|
+
data.tar.gz: 36f954ce80443aa56d0b80cd965bfbb394901f4a6bda5ed43d05ae305ab901cf3b1d6d726ce99e509c25ee529fe3273b56befc9643d3241521a8b69f44335914
|
data/README.md
CHANGED
@@ -25,14 +25,14 @@ Or install it yourself as:
|
|
25
25
|
Require the Javascript in your `application.js` (or other preferred) file via sprockets:
|
26
26
|
|
27
27
|
```javascript
|
28
|
-
//= require
|
28
|
+
//= require simple_form_autocomplete
|
29
29
|
```
|
30
30
|
|
31
|
-
|
31
|
+
Optionally import the CSS in your `application.css.scss` (or other preferred) file. For
|
32
32
|
sprockets-based apps:
|
33
33
|
|
34
34
|
```javascript
|
35
|
-
//= require
|
35
|
+
//= require simple_form_autocomplete
|
36
36
|
```
|
37
37
|
|
38
38
|
For SCSS imports:
|
@@ -3,8 +3,10 @@ require 'active_support/core_ext/hash/deep_merge'
|
|
3
3
|
module SimpleForm
|
4
4
|
module Inputs
|
5
5
|
class AutocompleteInput < Base
|
6
|
-
def input
|
7
|
-
|
6
|
+
def input(wrapper_options = nil)
|
7
|
+
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
8
|
+
|
9
|
+
@builder.text_field(attribute_name, merged_input_options) <<
|
8
10
|
@builder.hidden_field(attribute_name, hidden_html_options)
|
9
11
|
end
|
10
12
|
|
@@ -21,7 +23,7 @@ module SimpleForm
|
|
21
23
|
|
22
24
|
def hidden_html_options
|
23
25
|
{
|
24
|
-
value: options[:value]
|
26
|
+
value: options.key?(:value) ? options[:value] : hidden_tag_value
|
25
27
|
}
|
26
28
|
end
|
27
29
|
|
@@ -21,10 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'activesupport'
|
22
22
|
spec.add_dependency 'simple_form'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'actionpack'
|
25
|
-
spec.add_development_dependency 'activemodel'
|
26
24
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
27
25
|
spec.add_development_dependency 'nokogiri'
|
26
|
+
spec.add_development_dependency 'rails'
|
28
27
|
spec.add_development_dependency 'rake'
|
29
28
|
spec.add_development_dependency 'rspec'
|
30
29
|
end
|
@@ -8,9 +8,10 @@ describe SimpleForm::Inputs::AutocompleteInput do
|
|
8
8
|
|
9
9
|
let(:record) { Ingredient.new }
|
10
10
|
let(:collection) { %w[cup teaspoon tablespoon] }
|
11
|
+
let(:form_options) { {} }
|
11
12
|
let(:options) { {} }
|
12
13
|
let(:form) do
|
13
|
-
concat(simple_form_for(record) { |f|
|
14
|
+
concat(simple_form_for(record, form_options) { |f|
|
14
15
|
concat(f.input :name, { as: :autocomplete, source: ingredients_autocomplete_path }.merge(options))
|
15
16
|
concat(f.input :unit, { as: :autocomplete, source: collection }.merge(options))
|
16
17
|
})
|
@@ -86,5 +87,37 @@ describe SimpleForm::Inputs::AutocompleteInput do
|
|
86
87
|
expect(input.attribute('data-source').value).to eq ingredients_autocomplete_path
|
87
88
|
end
|
88
89
|
end
|
90
|
+
|
91
|
+
describe 'with wrapper options' do
|
92
|
+
before do
|
93
|
+
SimpleForm.setup do |config|
|
94
|
+
config.wrappers :custom, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
|
95
|
+
b.use :html5
|
96
|
+
b.use :placeholder
|
97
|
+
b.optional :maxlength
|
98
|
+
b.optional :pattern
|
99
|
+
b.optional :min_max
|
100
|
+
b.optional :readonly
|
101
|
+
b.use :label, class: 'control-label'
|
102
|
+
|
103
|
+
b.use :input, class: 'form-control'
|
104
|
+
b.use :error, wrap_with: { tag: 'span', class: 'help-block' }
|
105
|
+
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
let(:form_options) { { wrapper: :custom } }
|
111
|
+
|
112
|
+
it 'should maintain the custom wrapper class' do
|
113
|
+
div = subject.xpath('//div[contains(concat(" ", normalize-space(@class), " "), "ingredient_name")]')
|
114
|
+
expect(div.attribute('class').value).to match /\bform-group\b/
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should maintain the custom input class' do
|
118
|
+
input = subject.xpath('//input[@id="ingredient_name_autocomplete"]')
|
119
|
+
expect(input.attribute('class').value).to match /\bform-control\b/
|
120
|
+
end
|
121
|
+
end
|
89
122
|
end
|
90
123
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/helpers.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module AutocompleteSpecHelper
|
2
|
+
include ActionDispatch::Routing::UrlFor
|
2
3
|
include ActionController::RecordIdentifier if defined?(ActionController::RecordIdentifier)
|
3
4
|
include ActionView::RecordIdentifier if defined?(ActionView::RecordIdentifier)
|
4
5
|
include ActionView::Helpers::FormHelper
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_autocomplete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Huggins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -39,21 +39,21 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '1.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: nokogiri
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,21 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.3'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.3'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: nokogiri
|
70
|
+
name: rails
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - ">="
|
@@ -167,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
153
|
version: '0'
|
168
154
|
requirements: []
|
169
155
|
rubyforge_project:
|
170
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.4.5
|
171
157
|
signing_key:
|
172
158
|
specification_version: 4
|
173
159
|
summary: jQuery autocomplete for SimpleForm form fields
|