forked from nesquena/semantic_form_builder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
executable file
·99 lines (75 loc) · 3.83 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
SemanticFormBuilder
===================
Installation
============
To install, simply add a clone of the git repository to the vendor/plugins directory
$ cd /path/to/rails/app
$ git clone git://github.com/nesquena/semantic_form_builder.git vendor/plugins/semantic_form_builder
Overview
========
This plugin is a standardized form builder which works to create semantically correct forms, each field with the
appropriate label and wrapped within a definition list item in order to represent a list of items using proper xhtml markup.
Works with Rails 1.X as well as 2.X, including 2.2.2
The tags allowed are as follows:
* fieldset(name:string, &block) - wraps the rest of the form items in a definition list
* text_field (attribute:symbol, options_hash:hash)
* password_field (attribute:symbol, options_hash:hash)
* file_field (attribute:symbol, options_hash:hash)
* text_area (attribute:symbol, options_hash:hash)
* check_box (attribute:symbol, options_hash:hash)
* radio_buttons (attribute:symbol, options_hash:hash)
* submit_button (label:string) - create a submit button in a definition item
* image_submit_button (src:string) - create an image submit button in a definition item
These methods can be used within the context of a form builder or within any form as simple helper tags:
* semantic_form_for [ model-backed forms ]
* semantic_remote_form_for [ remote model-backed forms ]
* semantic_fields_for [ model-backed fields ]
* semantic_fieldset_tag [ non-model-backed forms ]
Example
=======
This form builder is rather easy to use as the example illustrates:
- semantic_form_for :user, :url => users_path do |f|
- f.fieldset 'Register' do
= f.text_field :login, :label => 'Login'
= f.text_field :email, :label => 'Email'
= f.password_field :password, :label => 'Password'
= f.password_field :password_confirmation, :label => 'Password Confirmation'
= f.submit_button 'Sign up'
which generates the following semantically valid markup:
<form method="post" action="/users">
<fieldset>
<legend>Register</legend>
<dl class = "semantic-form">
<dt><label for="user_login">Login:</label></dt>
<dd><input type="text" size="30" name="user[login]" id="user_login"/></dd>
<dt><label for="user_email">Email:</label></dt>
<dd><input type="text" size="30" name="user[email]" id="user_email"/></dd>
<dt><label for="user_password">Password:</label></dt>
<dd><input type="password" size="30" name="user[password]" id="user_password"/></dd>
<dt><label for="user_password_confirmation">Password Confirmation:</label></dt>
<dd><input type="password" size="30" name="user[password_confirmation]" id="user_password_confirmation"/></dd>
<dt class="button"/>
<dd class="button"><input type="submit" value="Sign up" name="commit"/></dd>
</dl>
</fieldset>
</form>
Other Examples
==============
Non-Model Backed Form
- form_tag some_url do
- semantic_fieldset_tag "Name" do |f|
= f.text_field_tag :username, :label => "Username"
= f.password_field_tag :password, :label => "Password"
= f.check_box_tag :is_admin, :label => "Administrator?"
= f.select_tag :category, @option_values
= f.submit_tag "Submit"
Remote Model Backed Form
- semantic_remote_form_for :user, :url => register_url do |u|
- u.fieldset do
= u.text_field "login"
= u.password_field "password"
= u.text_field "email"
= u.text_field "mobile_number", :label => "Mobile No"
= u.password_field "invite_code", :label => 'Invite'
= u.submit_button
Copyright (c) 2008 Nathan Esquenazi, released under the MIT license