formtastic_jquery_ui 0.0.2 → 0.0.3

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.
data/README.textile CHANGED
@@ -15,23 +15,18 @@ The autocomplete module adds jQuery UI's autocomplete widget to <code>belongs_to
15
15
 
16
16
  For best results use it with "Searchlogic":http://github.com/binarylogic/searchlogic and "Will Paginate":http://github.com/mislav/will_paginate as shown below
17
17
 
18
- <pre><code>
19
- class Product
18
+ <pre><code>class Product
20
19
  belongs_to :brand
21
20
  has_and_belongs_to_many :categories
22
- end
23
- </code></pre>
21
+ end</code></pre>
24
22
 
25
- <pre><code>
26
- class Category
23
+ <pre><code>class Category
27
24
  has_and_belongs_to_many :products
28
- end
29
- </code></pre>
25
+ end</code></pre>
30
26
 
31
27
  The search results should be mapped into value/label pairs for a JSON query
32
28
 
33
- <pre><code>
34
- class CategoriesController < ApplicationController
29
+ <pre><code>class CategoriesController < ApplicationController
35
30
  def index
36
31
  @search = Category.search(params[:search])
37
32
  @categories = @search.paginate(:page => params[:page])
@@ -40,51 +35,42 @@ class CategoriesController < ApplicationController
40
35
  format.json { @categories.map { |category| {:label => category.title, :value => category.id} }.to_json }
41
36
  end
42
37
  end
43
- end
44
- </pre></code>
38
+ end</code></pre>
45
39
 
46
- <pre><code>
47
- class Brand
40
+ <pre><code>class Brand
48
41
  has_many :products
49
- end
50
- </code></pre>
42
+ end</code></pre>
51
43
 
52
- <pre><code>
53
- class BrandsController < ApplicationController
44
+ <pre><code>class BrandsController < ApplicationController
54
45
  def index
55
46
  @search = Brand.search(params[:search])
56
47
  @brands = @search.paginate(:page => params[:page])
57
48
  respond_to do |format|
58
49
  format.html {}
59
- format.json { @brands.map { |brand| {:label => brand.name, :value => brand.id} }.to_json }
50
+ format.json { render :json => @brands.map { |brand| {:label => brand.name, :value => brand.id} }.to_json }
60
51
  end
61
52
  end
62
- end
63
- </pre></code>
53
+ end</code></pre>
64
54
 
65
55
  The input method takes two extra parameters:
66
56
 
67
57
  * <code>:url</code> - the URL of the data source (JSON formatted)
68
58
  * <code>:param_name</code> - the parameter that will be passed to the URL (as part of the search param)
69
59
 
70
- <pre><code>
71
- <% semantic_form_for @product do |f| %>
60
+ <pre><code><% semantic_form_for @product do |f| %>
72
61
  <% f.inputs do %>
73
62
  <%= f.input :categories, :as => :autocomplete, :url => categories_path(:format => :json), :param_name => 'title_begins_with' %>
74
63
  <%= f.input :brand, :as => :autocomplete, :url => brands_path(:format => :json), :param_name => 'name_begins_with' %>
75
64
  <% end %>
76
- <% end %>
77
- </code></pre>
65
+ <% end %></code></pre>
78
66
 
79
- h2. Datepicker
67
+ h3. Datepicker
80
68
 
81
- <pre><code>
82
- <% semantic_form_for @todo do |f| %>
69
+ <pre><code><% semantic_form_for @todo do |f| %>
83
70
  <% f.inputs do %>
84
71
  <%= f.input :due_date, :as => :datepicker
85
72
  <% end %>
86
- <% end %>
87
- </code></pre>
73
+ <% end %></code></pre>
88
74
 
89
75
  h2. Requirements
90
76
 
@@ -44,8 +44,9 @@ module FormtasticJQueryUI
44
44
  });
45
45
  EOT
46
46
  end
47
- elsif reflection && [:belongs_to].include?(reflection.macro)
48
- html << self.hidden_field(reflection.primary_key_name)
47
+ elsif (reflection && [:belongs_to].include?(reflection.macro)) || reflection.nil?
48
+ hidden_field_name = reflection.try(:primary_key_name) || "#{method}_id"
49
+ html << self.hidden_field(hidden_field_name)
49
50
  html << template.text_field_tag(input_name, object.send(method).try(detect_label_method([object.send(method)])))
50
51
  html << template.content_tag(:script, :type => 'text/javascript') do
51
52
  <<-EOT
@@ -63,7 +64,7 @@ EOT
63
64
  });
64
65
  },
65
66
  select: function(event, selection) {
66
- $('##{sanitized_object_name}_#{reflection.primary_key_name}').val(selection.item.value);
67
+ $('##{sanitized_object_name}_#{hidden_field_name}').val(selection.item.value);
67
68
  $('##{input_name}').val(selection.item.label);
68
69
  return false;
69
70
  },
@@ -71,7 +72,7 @@ EOT
71
72
  });
72
73
  $('##{input_name}').blur(function(event){
73
74
  if($(this).val() == '')
74
- $('##{sanitized_object_name}_#{reflection.primary_key_name}').val('');
75
+ $('##{sanitized_object_name}_#{hidden_field_name}').val('');
75
76
  })
76
77
  EOT
77
78
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic_jquery_ui
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Paul Smith
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-23 00:00:00 +01:00
18
+ date: 2010-12-16 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: 1.1.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
- description: Currently provides autocomplete and datepicker widgets
37
+ description:
38
38
  email: paul@elandesign.co.uk
39
39
  executables: []
40
40
 
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: 1.3.4
85
85
  requirements: []
86
86
 
87
- rubyforge_project: formtastic_jquery_ui
87
+ rubyforge_project:
88
88
  rubygems_version: 1.3.7
89
89
  signing_key:
90
90
  specification_version: 3