vidl-toolbox 0.0.10 → 0.0.11

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.
@@ -285,14 +285,30 @@ module Toolbox
285
285
  edit_config(rec).controlsets.each do |controlset|
286
286
  controlset.widget_list.widgets.each do |widget|
287
287
  case widget.type
288
- when :auto_complete
289
- value = params.delete widget.name
290
- params[widget.name.to_s.foreign_key] = nil if value == '' || value == nil
288
+ when :auto_complete
289
+ if controlset.collection_config
290
+ # remove autocomplete text field for new or existing entries
291
+ a = Toolbox::Helpers.collection_attribute_name(controlset.collection_config, rec)
292
+ coll = params[a]
293
+ if coll
294
+ coll.each { |p| remove_autocomplete_text p, widget} if coll.is_a? Array
295
+ coll.each_key { |p| remove_autocomplete_text p, widget} if coll.is_a? Hash
296
+ end
297
+ if rec # may also have new entries...
298
+ a = Toolbox::Helpers.collection_attribute_name(controlset.collection_config, nil)
299
+ coll = params[a]
300
+ coll.each { |p| remove_autocomplete_text p, widget} if coll
301
+ end
302
+ else
303
+ remove_autocomplete_text params, widget
304
+ end
291
305
  when :date
292
306
  #params[widget.name] = Date.strptime(params[widget.name], '%d.%m.%y')
293
307
  end
294
308
  end
295
309
  end
310
+ puts 'After preprocessing:'
311
+ puts params.inspect
296
312
  params
297
313
  end
298
314
 
@@ -309,6 +325,11 @@ module Toolbox
309
325
 
310
326
  private
311
327
 
328
+ def remove_autocomplete_text param, widget
329
+ value = param.delete widget.name
330
+ param[widget.name.to_s.foreign_key] = nil if value == '' || value == nil
331
+ end
332
+
312
333
  def set_record obj
313
334
  instance_variable_set "@#{model_name}".to_sym, obj
314
335
  end
@@ -3,7 +3,7 @@ module Toolbox
3
3
  module Helpers
4
4
 
5
5
  def self.collection_attribute_name collection_config, rec
6
- new_or_existing = rec.new_record? ? 'new' : 'existing'
6
+ new_or_existing = rec && !rec.new_record? ? 'existing' : 'new'
7
7
  "#{new_or_existing}_#{collection_config.type.name.to_s.underscore}_attributes"
8
8
  end
9
9
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Toolbox
3
- VERSION = '0.0.10'
3
+ VERSION = '0.0.11'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidl-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Nyffenegger