Coder Social home page Coder Social logo

forms-fu's Introduction

forms-fu
======================

this plugin is intended to help in creating forms. its featureset will grow in the near future. for now it can do this:

* adds a required_field?(field_name) method to all the activerecord models. this allows you to automatically mark required fields in a form with a *. required fields are determined automatically from the validates_* calls in the class.

* there is a helper method available in the views that prints out the label for a field with our without star

* a TabularForumBuilder class which can be used with the form_for rails helper. It automatically wraps all form fields in table rows and cells.


Examples
=======

# user.rb

class User < ActiveRecord::Base
  validates_presence_of :name
  validates_confirmation_of :password
  validates_acceptance_of :terms
  
  required_fields << [:login] # in case you want to mark additional fields as required
end

User.required_field?(:name) # => true
User.required_field?(:login) # => true
User.required_field?(:password_confirmation) # => true
User.required_field?(:terms) # => true
User.required_field?(:email) # => false


# users/new.html.erb

<%= label_fu @user, :name %> # => <label for="user_name">Name *</label>
<%= label_fu @user, :email %> # => <label for="user_email">Email</label>

# or with the form builder

<%- form_for :user, :builder => TabularFormBuilder do |f| -%>
  <table>
  <%= f.text_field :name %>
  </table>
<%- end -%>

# prints out:

<form ...>
  <table>
    <tr>
      <th><label for="user_name">Name: *</label></th>
      <td><input name="user[name]" type="text"/></td>
    </tr>
  </table>
</form>

# some added sugar:

<%= f.text_fields :email, :name, :address %>

# call text_field for each of the attributes

<%= f.text_field_without_label :name %>

# prints out the input tag without the tr, td and label - in case you need more customization

For questions, patches etc. contact alex[at]upstream-berlin.com

Copyright (c) 2008 Alexander Lang, released under the MIT license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.