Code Monkey home page Code Monkey logo

air_budd_form_builder's Introduction

AirBuddFormBuilder

A form builder that generates semantic HTML as advocated by Andy Budd in CSS Mastery.

It generates Wufoo-style buttons and links for submitting the form, cancelling it, etc. These buttons and links use several icons from the FAMFAMFAM set. You can choose not to use them if you don't want to.

Please send feedback to [email protected].

HAML

Thanks to David Baldwin, this form builder can be used with HAML.

ERB Example

app/views/projects/new.html.erb:

<% airbudd_form_for @project do |f| %>
  <%= f.text_field :title, :required => true, :name => "Article's Title" %>
  <% f.buttons do |b| %>
    <%= b.save %>
    <%= b.cancel :url => projects_path %>
  <% end %>
<% end %>

This renders:

<form ...> <!-- standard Rails form element -->
  <p class="text">
    <label for="article_title">Article's Title:
      <em class="required">(required)</em>
    </label>
    <input id="article_title" name="article[title]" type="text" value=""/>
  </p>
  <div class="buttons">
    <button type="submit" class="positive"><img src="/images/icons/tick.png" alt=""/> Save</button>
    <a href="/projects"><img src="/images/icons.pencil.png" alt=""/> Cancel</a>
  </div>
</form>

And if the field's value is invalid:

<p class="error text">
  <label for="article_title">Article's Title:
    <em class="required">(required)</em>
    <span class="feedback">can't be blank</span>
  </label>
  <input id="article_title" name="article[title]" type="text" value=""/>
</p>

See Mr Budd's good book for discussion of the HTML and the CSS to go with it.

Configuration

Thanks to Dan Webb, whose Enhanced Form Builder configuration I borrowed.

You can configure the form builder at three levels: app-wide, per-form, and per-field. The per-field configuration differs slightly from the other two.

  • App-wide:

config/initializers/form_builder.rb:

AirBlade::AirBudd::FormBuilder.default_options.merge!({
  :required_signifier => '*',
  :label_suffix => '',
})
  • Per form:

In your form:

- airbudd_form_for @member do |f|
  - f.required_signifier = '*'
  = f.text_field :name
  • Per field:

On a form field:

= f.text_field :name, :required => true, :suffix => ''

See the comments in the form builder's code for the exact configuration options available.

To Do

  • Fix country_select so it handles priority countries and options. It's currently broken.
  • Wrapper for options_group_from_collection_for_select.
  • DRY way to show consistent form links, e.g. edit, outside a form.
    • include link_to_function, link_to_remote, etc.
    • Cf AirBlade::AirBudd::FormHelper#link_to_form.
    • Do we need to wrap buttons/links in a div? (Probably semantically good to do so?)
  • Two read-only field helpers: one for within a form, containing the value so it can be submitted, and one for the 'show' page, so we can use the same markup and CSS (c.f. http://tomayko.com/writings/administrative-debris)..
  • Example CSS:
    • for Wufoo-style buttons and links.
    • for CSS Mastery XHTML.
  • Summary error messages.
  • Consider how to handle multiple actions, e.g. 'save & create another', 'save & keep editing'. See Brandon Keepers's with_action plugin.

Copyright (c) 2007 Andrew Stewart, 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.