Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated README

Signed-off-by: Ryan Heath <rpheath@gmail.com>
  • Loading branch information...
commit 8d95b733e7457f071db88f1fabe94e3fd3272b34 1 parent b02e211
@scharfie scharfie authored committed
Showing with 21 additions and 3 deletions.
  1. +16 −0 README.textile
  2. +5 −3 lib/form_assistant.rb
View
16 README.textile
@@ -95,6 +95,22 @@ Another convenient thing about the form assistant is the ability to control labe
That works for all form helpers (text_area, check_box, etc). And by default, the label will be the humanized version of the field name, so that's what you'll get if you ignore the label options altogether.
+h3. Form Widgets
+
+Sometimes, a single form field isn't enough. Form assistant provides a construct to help you
+with this, called widget:
+
+<pre><code><% form.widget :expiration_date, :label => 'Card expiration date' do %>
+ <%= form.select :expiration_month, (1..12) %>
+ <%= form.select :expiration_month, (1..12) %>
+<% end %></code></pre>
+
+There are a few things to note about this new feature:
+
+ * error messages will come from the errors on the field name ('expiration_date' in the above example)
+ * templates and labels are disabled for the duration of the block
+ * the default template for widgets is the fallback template (===_field.html.erb=== unless configured otherwise)
+
h3. Custom Helpers
The form assistant provides a #cancel() helper that will allow the user to go back to the previous screen, automatically.
View
8 lib/form_assistant.rb
@@ -136,7 +136,7 @@ def extract_options_for_label(field, options={})
# consider the global setting for labels and
# allow for turning labels off on a per-helper basis
# <%= form.text_field :title, :label => false %>
- if self.class.ignore_labels || options[:label] === false
+ if self.class.ignore_labels || options[:label] === false || field.blank?
label_options[:label] = false
else
# ensure that the :label option is a Hash from this point on
@@ -190,8 +190,9 @@ def without_assistance(options={}, &block)
result
end
- def widget(field, *args, &block)
+ def widget(*args, &block)
options = args.extract_options!
+ field = args.shift || nil
label_options = extract_options_for_label(field, options)
template_options = extract_options_for_template(self.fallback_template, options)
label = label_options[:label] === false ? nil : self.label(field, label_options.delete(:text), label_options)
@@ -202,7 +203,8 @@ def widget(field, *args, &block)
@template.capture(&block)
end
- render_partial_for(element, field, label, tip, template_options[:template], 'widget', required, args)
+ partial = render_partial_for(element, field, label, tip, template_options[:template], 'widget', required, args)
+ RPH::FormAssistant::Rules.binding_required? ? @template.concat(partial, block.binding) : @template.concat(partial)
end
# redefining all traditional form helpers so that they
Please sign in to comment.
Something went wrong with that request. Please try again.