my wrapper doesn't seems to be taken in account ...

139 views
Skip to first unread message

erwin

unread,
May 31, 2012, 6:40:12 PM5/31/12
to SimpleForm
I am displaying a list of checkboxes ( from an has_many association )

= f.collection_check_boxes :category_ids,
Category.all, :id, :name, :item_wrapper_tag
=> :p, :item_wrapper_class => "blog-category", :wrapper
=> :checkbox

the checkboxes are listed , but the input box is above the label and
not inline .....

I am using the following wrapper ( input and label should be on the
same line , as being span left....)

config.wrappers :checkbox, :tag => 'div', :class => 'control-
group', :error_class => 'error' do |b|
b.wrapper :tag => 'div', :class => 'controls' do |ba|
ba.use :input, :wrap_with => { :tag => :span, :class => 'left'}
ba.use :label, :wrap_with => { :tag => :span, :class => 'left'}
ba.use :error, :wrap_with => { :tag => :span, :class => 'help-
block' }
ba.use :hint, :wrap_with => { :tag => :p, :class => 'help-
block' }
end
end

and the html output is :

<p class="blog-category">
<input type="checkbox" value="2" name="article[category_ids][]"
id="article_category_ids_2">
<label for="article_category_ids_2"
class="collection_check_boxes">Général</label>
</p>
<p class="blog-category">
<input type="checkbox" value="4" name="article[category_ids][]"
id="article_category_ids_4">
<label for="article_category_ids_4"
class="collection_check_boxes">Particulier</label>
</p>
<p class="blog-category">
<input type="checkbox" value="3" name="article[category_ids][]"
id="article_category_ids_3">
<label for="article_category_ids_3"
class="collection_check_boxes">Spécifique</label>
</p>
<input type="hidden" value="" name="article[category_ids][]">

what's wrong with it ?
thanks for your feedback
.

Rafael Mendonça França

unread,
May 31, 2012, 6:41:26 PM5/31/12
to plataformate...@googlegroups.com
Did you restarted the server after you create the wrapper?

erwin

unread,
Jun 1, 2012, 1:51:46 AM6/1/12
to SimpleForm
yes, this wrapper has been created weeks ago and is running fine for
stand-alone checkboxes...
should I use a block to layout each item ?



On Jun 1, 12:41 am, Rafael Mendonça França <rafaelmfra...@gmail.com>
wrote:
> Did you restarted the server after you create the wrapper?
>
> Rafael Mendonça Françahttp://twitter.com/rafaelfrancahttps://github.com/rafaelfranca

erwin

unread,
Jun 1, 2012, 2:27:03 AM6/1/12
to SimpleForm
it seems that I should use the f.association .... I get the
check_boxes correctly displayed

THIS WORKS FINE...
= f.association :categories, :as => :check_boxes, :item_wrapper_tag
=> :p, :item_wrapper_class => "blog-category", :wrapper
=> :checkbox
however I have an additional label displayed .. which I need to find
how to get rid of it ..

<div class="control-group check_boxes optional">
<div class="controls">

<span class="left">

<label class="checkbox blog-category">
<input type="checkbox" value="2" name="article[category_ids][]"
id="article_category_ids_2" class="check_boxes optional">Generic
</label>

<label class="checkbox blog-category">
<input type="checkbox" value="4" name="article[category_ids][]"
id="article_category_ids_4" class="check_boxes optional">Particular
</label>

<label class="checkbox blog-category">
<input type="checkbox" value="3" name="article[category_ids][]"
id="article_category_ids_3" class="check_boxes optional">Specific
</label>

<input type="hidden" value="" name="article[category_ids][]">

</span>

# HOW TO GET RID of this additional label ?
<span class="left">
<label class="check_boxes optional control-label">Categories</label>
</span>

</div>
</div>

erwin

unread,
Jun 1, 2012, 2:48:54 AM6/1/12
to SimpleForm
[SOLVED]
Got it .. I am using Bootstrap CSS ,and w the latest version of
Simple_form , I can get rid of it and go with the standard wrapper...
so a simple :
= f.association :categories, :as => :check_boxes did it !


On Jun 1, 7:51 am, erwin <kadou...@gmail.com> wrote:

Carlos Antonio da Silva

unread,
Jun 1, 2012, 7:18:29 AM6/1/12
to plataformate...@googlegroups.com
Yes, that's right. f.collection_check_boxes is a normal helper added to Rails, the same as f.collection_select for instance, so it does not contain anything that SimpleForm provides (i.e. label / wrapper / error). f.association, on the other hand, is the one that gives you all this and *uses* collection_check_boxes internally to build the collection.

So you're right, go with f.association :)

-- 
At.
Carlos Antonio

Reply all
Reply to author
Forward
0 new messages