activeadmin_select_many 0.2.0 → 0.2.2

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
  SHA1:
3
- metadata.gz: dc928a64768e531eb353bfb5aecc59b92151a4ff
4
- data.tar.gz: 8b4ff87b759f176fa8f1d0a0806e5bff7be878be
3
+ metadata.gz: 7542c90490f2781e2091e54c43684e969039bb3a
4
+ data.tar.gz: 8707be738dc243eca090ed17624a3d11bb1492ea
5
5
  SHA512:
6
- metadata.gz: 7b754c3cf2c094ea2eec2d805b8cf99b760680d74471fadcaa35ea8fe4437d0e05f75bded2ac68e817722b9005e093db3e84f44102d0abd8eacfbf8846c7f1fc
7
- data.tar.gz: 6244aa2b14352c08cc696319dc93f49d79c44a49f59d8176d572cfc8c71f5aa12e9786a912bc180e98012367be57ee5b6cfb08bf6dd00ca0203e518bead4991c
6
+ metadata.gz: 5f36c599c3c0ed7e8a6200fe17bc6844abce252078c1b5ca09d4a97d4c7b789972d81feb97d70307f26d51f20c541e737e21eaff9d2604c4a5d32df8a7dd3396
7
+ data.tar.gz: 1ed71c037e71efbb65a65decbc3318dc103ed7b3927c9b38de46e84394eba07f25ca9a897eab2f5c8a5971fc55c0c15fcada3d3a2b24b353f531e76d39be3524
data/README.md CHANGED
@@ -34,13 +34,14 @@ Features for *select_one*:
34
34
  ## Options
35
35
 
36
36
  - **collection**: local collection
37
+ - **counter_limit**: if results count is greater than or equal to this limit a '+' is shown
37
38
  - **filter_form**: for *select_one* only, allow to use it as filter
39
+ - **member_label**: key to use as text for select options
38
40
  - **placeholder**: placeholder string for search box
39
41
  - **remote_collection**: JSON path
40
42
  - **search_param**: parameter to use as search key (ransack format)
41
- - **sortable**: set to true to enable sortable buttons (default: not set)
42
43
  - **size**: number of rows of both the selects (default: 4)
43
- - **text_key**: key to use as text for select options
44
+ - **sortable**: set to true to enable sortable buttons (default: not set)
44
45
 
45
46
  ## Example with select_many
46
47
 
@@ -51,7 +52,7 @@ Add to ActiveAdmin model config, in *form* block.
51
52
  - Remote collection (using AJAX):
52
53
  `f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json )`
53
54
  - Changing search param and text key (default: *name*):
54
- `f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json ), search_param: 'category_contains', text_key: 'category', placeholder: 'Type something...'`
55
+ `f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json ), search_param: 'category_contains', member_label: 'category', placeholder: 'Type something...'`
55
56
  - Sortable (items position must be saved manually):
56
57
  `f.input :tags, as: :select_many, remote_collection: admin_tags_path( format: :json ), sortable: true`
57
58
 
@@ -84,11 +85,11 @@ end
84
85
 
85
86
  In a form:
86
87
 
87
- `f.input :article, as: :select_one, placeholder: 'Search...', remote_collection: admin_articles_path( format: :json ), search_param: 'title_contains', text_key: 'title'`
88
+ `f.input :article, as: :select_one, placeholder: 'Search...', remote_collection: admin_articles_path( format: :json ), search_param: 'title_contains', member_label: 'title'`
88
89
 
89
90
  As filter:
90
91
 
91
- `filter :article_id_eq, as: :select_one, filter_form: true, placeholder: 'Search...', search_param: 'title_contains', text_key: 'title', remote_collection: '/admin/articles.json'`
92
+ `filter :article_id_eq, as: :select_one, filter_form: true, placeholder: 'Search...', search_param: 'title_contains', member_label: 'title', remote_collection: '/admin/articles.json'`
92
93
 
93
94
  ## Do you like it? Star it!
94
95
 
@@ -111,6 +111,7 @@ $(document).ready( function() {
111
111
  var search_key = $(this).data('search') ? $(this).data('search') : 'name_contains';
112
112
  var value_key = $(this).data('value') ? $(this).data('value') : 'id';
113
113
  var text_key = $(this).data('text') ? $(this).data('text') : 'name';
114
+ var counter_limit = $(this).data('counter-limit') ? Number( $(this).data('counter-limit') ) : 0;
114
115
  data['q['+search_key+']'] = $(this).val();
115
116
  $.ajax({
116
117
  context: select,
@@ -125,7 +126,7 @@ $(document).ready( function() {
125
126
  data.forEach( function( item ) {
126
127
  sel.append( $('<option>', { value: item[value_key], text: item[text_key] }) );
127
128
  });
128
- sel.parent().find( '.status' ).text( '[' + data.length + ']' );
129
+ sel.parent().find( '.status' ).text( '[' + data.length + ( counter_limit > 0 && data.length >= counter_limit ? '+' : '' ) + ']' );
129
130
  },
130
131
  });
131
132
  }
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module SelectMany
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
@@ -40,7 +40,7 @@ module Formtastic
40
40
  end
41
41
 
42
42
  def search_box_html
43
- @opts ||= {id: nil, class: 'search-select', placeholder: options.delete( :placeholder ), 'data-remote-collection': options[:'data-remote-collection'], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:text_key] ? options[:text_key] : 'name', 'data-value': options[:value_key] ? options[:value_key] : 'id'}
43
+ @opts ||= {id: nil, class: 'search-select', placeholder: options.delete( :placeholder ), 'data-remote-collection': options[:'data-remote-collection'], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:member_label] ? options[:member_label] : ( options[:text_key] ? options[:text_key] : 'name' ), 'data-value': options[:value_key] ? options[:value_key] : 'id'}
44
44
  template.text_field_tag( nil, '', @opts )
45
45
  end
46
46
 
@@ -26,7 +26,8 @@ module Formtastic
26
26
  end
27
27
 
28
28
  def search_box
29
- @opts ||= {id: nil, class: 'search-select', placeholder: options[:placeholder], 'data-remote-collection': options[:remote_collection], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:text_key] ? options[:text_key] : 'name', 'data-value': options[:value_key] ? options[:value_key] : 'id', 'data-msg': options[:msg_items]}
29
+ # TODO: remove text_key in next major version
30
+ @opts ||= {id: nil, class: 'search-select', placeholder: options[:placeholder], 'data-remote-collection': options[:remote_collection], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:member_label] ? options[:member_label] : ( options[:text_key] ? options[:text_key] : 'name' ), 'data-value': options[:value_key] ? options[:value_key] : 'id', 'data-msg': options[:msg_items], 'data-counter-limit': options[:counter_limit].to_i }
30
31
  template.text_field_tag( nil, '', @opts )
31
32
  end
32
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_select_many
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-30 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin