:checked=>"checked" in input_html?

44 views
Skip to first unread message

kedar mhaswade

unread,
Jan 21, 2012, 9:31:37 AM1/21/12
to plataformatec-simpleform
I am a bit puzzled.

With my model's Boolean field (a virtual attribute named "timed", really)  is:
<% if timed? %>
  <% f.input :timed, :as=> :boolean, :input_html => {:checked => "checked"} %>
<% else %>
  <% f.input :timed, :as=> :boolean %>
<% end %>

the only way to initialize it such that its rendering reflects its state? Is there something like :checked => true available on a checkbox input?

Regards,
Kedar

PS - I never understood why HTML adhered to this almost meaningless checked = "checked" attribute for checkboxes.

Vasiliy Ermolovich

unread,
Jan 21, 2012, 10:02:33 AM1/21/12
to SimpleForm
Hey, kedar. Actually, it should work with just plain <%
f.input :timed, :as=> :boolean %> if timed is an attribute of some
model. For example:

<%= simple_form_for(@product) do |f| %>
<%= f.input :timed, :as=> :boolean %>
<%= f.submit %>
<% end %>

class Product < ActiveRecord::Base
attr_accessor :timed
end

so if you set @product.timed = true in your controller your checkbox
will be checked.

kedar mhaswade

unread,
Jan 21, 2012, 8:16:43 PM1/21/12
to plataformate...@googlegroups.com
On Sat, Jan 21, 2012 at 7:02 AM, Vasiliy Ermolovich <you...@gmail.com> wrote:
Hey, kedar. Actually, it should work with just plain <%
f.input :timed, :as=> :boolean %> if timed is an attribute of some
model. For example:

<%= simple_form_for(@product) do |f| %>
 <%= f.input :timed, :as=> :boolean  %>
 <%= f.submit %>
<% end %>

class Product < ActiveRecord::Base
 attr_accessor :timed
end

so if you set @product.timed = true in your controller your checkbox
will be checked.

Thanks Vasilly!
Reply all
Reply to author
Forward
0 new messages