Class: Formtastic::Inputs::FakeInput

Inherits:
Object
  • Object
show all
Includes:
Base, Base::Stringish
Defined in:
lib/formtastic/inputs/fake_input.rb

Overview

Outputs a simple ‘<label>` with a `<span />` wrapped in the standard `<li>` wrapper. This is useful when you need to show read-only value in the form using all regular input decorations, but without the ability to pass its value in the form POST request. Use the `:value` option to set custom value.

Examples:

Full form context and output


<%= semantic_form_for(@user) do |f| %>
  <%= f.inputs do %>
    <%= f.input :id, :as => :fake %>
    <%= f.input :tax_class,  :as => :fake, :value => "Class #{f.object.tax_class}"
    <%= f.input :first_name, :as => :string %>
  <% end %>
<% end %>

<form...>
  <fieldset>
    <ol>
      <li class="fake">
        <label for="user_id">Id</label>
        <span id="user_id">123</span>
      </li>
      <li class="fake">
        <label for="user_tax_class">Id</label>
        <span id="user_tax_class">Class 5</span>
      </li>
      <li class="string">
        <label for="user_first_name">First name</label>
        <input type="text" id="user_first_name" name="user[first_name]">
      </li>
    </ol>
  </fieldset>
</form>

See Also:

  • InputsHelper#input for full documentation of all possible options.

Instance Method Summary collapse

Instance Method Details

#to_htmlObject



43
44
45
46
47
# File 'lib/formtastic/inputs/fake_input.rb', line 43

def to_html
  input_wrapping do
    label_html << content_html
  end
end