Skip to content

michaelkl/formtastic-fake_input

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 

Formtastic FakeInput

Fake input class for Formtastic.

It generates <span> tags for data values instead of <input>s.

This is useful when you need to show read-only value in the resource edit form using all regular input decorations, giving user a clear understanding of its "readonly-ness" and without the ability to pass its value in the form POST request.

It outputs a simple <label> with a <span /> wrapped in the standard <li> wrapper.

You can also use the :value option to set custom value.

Usage example

<%= 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>

Copyright

Copyright © 2018 Michael Klimenko. See LICENSE for details.

About

Fake input class for Formtastic

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages