From c81a09dc40cd403b261a54b98d108f49dde391a8 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Thu, 10 Apr 2014 11:32:12 -0300 Subject: [PATCH] Improve the wrapper_mappings explanation. --- app/views/documentation/index.html.erb | 41 ++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/app/views/documentation/index.html.erb b/app/views/documentation/index.html.erb index 834d7933..c41ef513 100644 --- a/app/views/documentation/index.html.erb +++ b/app/views/documentation/index.html.erb @@ -24,33 +24,50 @@

Example: Lets build the following form.

+ -
- <%= image_tag 'simple_form_bootstrap_form_example.png' %> -
+
+ <%= image_tag 'simple_form_bootstrap_form_example.png' %> +
+

The code is straightforward and looks like this:

-
- <%= image_tag 'basic_form_example.png' %> -
+ <%= image_tag 'basic_form_example.png' %> +
+

- Note that the code is very simple, and the only think you have to set is - the wrapper option inside each field. + The code is very simple, isn't it?

But it can get better! We can use the wrapper_mapping option - to remove this duplication. Lets see how our code will look like. + to remove that wrapper duplication. This option receives a Hash containing an input + type and the wrapper that will be used for all inputs with specified type.

-
- <%= image_tag 'improved_form_example.png' %> -
+

+ Example: +

+ { string: :string_wrapper, boolean: :boolean_wrapper } +

+ + All the String inputs will now use the :string_wrapper, and the + same applies to boolean fields, which will use the :boolean_wrapper + for all its inputs. + You can see more information about wrapper_mappings + <%= link_to 'here.', 'https://github.com/plataformatec/simple_form/blob/master/lib/simple_form.rb#L125-L131' %> +

+
+ +
+ <%= image_tag 'improved_form_example.png' %> +
+

Simple, right? You can see the code for the other examples <%= link_to 'on github.', 'https://github.com/rafaelfranca/simple_form-bootstrap' %>