DataMapper Forms

DataMapper model form generation.

Features:

  • Integrates with DataMapper

  • Fast; over 1000 elements in 0.1 seconds (rake benchmark)

  • Error reporting

  • Handles restful HTTP verbs

  • Provides low-level form elements uncoupled from DataMapper

Examples:

Pretend in a magical world we have a User model, and only the email is valid while we are updating. Based on the situation above, the form would render similar to the markup beneath the example.

errors_for @user
form_for @user, :action => '/user' do |f|
  f.textfield :name, :label => 'Name'
  f.textfield :email, :label => 'Email'
  f.submit :op, :value => 'Update'
end

<ul class="messages error">
  <li>Name has an invalid format</li>
</ul>
<form action="/user" method="post" id="form-user">
  <input type="hidden" name="_method" value="put" />
  <label for="name">Name:</label>
  <input type="textfield" class="error form-textfield form-name" name="name" />
  <label for="email">Email:</label>
  <input type="textfield" class="form-textfield form-email" name="email" />
  <input type="submit" class="form-submit form-op" value="Update" name="op" />
</form>

License:

(The MIT License)

Copyright © 2008 TJ Holowaychuk

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, an d/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.