ransack_ui 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,7 +65,7 @@
65
65
  else
66
66
  predicate_select2.show()
67
67
  # If Select2 is on query input, remove and set defaults
68
- if query_select2 = @element.find("#s2id_#{base_id}v_0_value")
68
+ if (query_select2 = @element.find("#s2id_#{base_id}v_0_value")).length > 0
69
69
  query_input.select2('destroy')
70
70
  query_input.val('')
71
71
  previous_val = ''
@@ -181,20 +181,27 @@
181
181
  @add_query_input(target, base_name, i + 1, v)
182
182
 
183
183
  setup_multi_query_input: (predicate_el, query_el, multi_id) ->
184
- # Hide query input
185
- query_el.hide()
186
184
  base_name = predicate_el.attr('name').slice(0, -3) + '[v]'
187
185
  query_el.after(
188
186
  $('<input class="ransack_query_multi" id="' + multi_id + '" ' +
189
187
  'style="width:' + (query_el.width() * 2) + 'px;" ' +
190
188
  'data-base-name="' + base_name + '" />'))
191
189
 
190
+ # Fetch all existing values
191
+ inputs = @element.find("input[name^=\"#{base_name}\"]")
192
+ values = $.map inputs, (el) ->
193
+ el.value
194
+ # Hide all query inputs
195
+ inputs.hide()
196
+
192
197
  # Find newly created input and setup Select2
193
- @element.find('#' + multi_id).select2
198
+ multi_query = @element.find('#' + multi_id)
199
+ multi_query.select2
194
200
  tags: []
195
201
  tokenSeparators: [',']
196
202
  formatNoMatches: (t) ->
197
203
  "Add a search term"
204
+ multi_query.select2('val', values)
198
205
 
199
206
  add_query_input: (base_input, base_name, id, value) ->
200
207
  base_input.after $('<input name="'+base_name+'['+id+'][value]" '+
@@ -253,7 +260,7 @@
253
260
  allowClear: true
254
261
  formatSelection: (object, container) ->
255
262
  # Return 'Model: field' unless column is on root model
256
- if $(object.element).data('root-model')
263
+ if !object.element || $(object.element).data('root-model')
257
264
  object.text
258
265
  else
259
266
  group_label = $(object.element).parent().attr('label')
@@ -261,7 +268,7 @@
261
268
  if group_label == object.text
262
269
  object.text
263
270
  else
264
- $(object.element).parent().attr('label') + ': ' + object.text
271
+ group_label + ': ' + object.text
265
272
 
266
273
  init_datetimepicker: (base_id) ->
267
274
  if $.ui?.timepicker?
@@ -16,7 +16,7 @@ module Ransack
16
16
  if bases.size > 1
17
17
  @template.select(
18
18
  @object_name, :name,
19
- @template.grouped_options_for_select(attribute_collection_for_bases(bases)),
19
+ @template.grouped_options_for_select(attribute_collection_for_bases(bases), object.name),
20
20
  objectify_options(options), @default_options.merge(html_options)
21
21
  )
22
22
  else
@@ -1,3 +1,3 @@
1
1
  module RansackUI
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-16 00:00:00.000000000 Z
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ransack_chronic
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: 4299301087477081386
79
+ hash: 1445871146542449388
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: 4299301087477081386
88
+ hash: 1445871146542449388
89
89
  requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 1.8.24