activescaffold/active_scaffold — pull request #173 by Envek (2012-07-13 06:12:49+00:00)
Title: Add HTML5 form fields

Hi, everyone. I've added support for some new html 5 fields and attributes. Primarily to allow browsers validate contents before form submit. And for better user experience in modern browsers.

New types: `:url`, `:email`, `:telephone`, `:number` and `:range`

They are described here: http://diveintohtml5.info/forms.html

For `:number` and `:range` AS automatically searches for constraints, defined in validators, and automatically sets `min`, `max` and `step` attributes for HTML `input` tag.

And last, I've added support for `placeholder` and `required` attributes.

None of that applies automatically. (But it's possible to make number values `:number`'s automatically, should I do so?)

Only modern browsers supports all these cool features, old browsers just renders old plain `` tags.

**Example 1:**

stub.rb:
```ruby
validates :value, :numericality => {
:greater_than_or_equal => 4,
:even => true
}
```
stubs_controller.rb
```ruby
conf.columns[:value].form_ui = :number
```
result (note the `min` and `step` attributes):
```html

```
Browser doesn't allow to send a form with wrong values.

![Spinbox control with validation](http://habrastorage.org/storage2/462/4ae/312/4624ae312c9e44d2e680f3986c694d46.png "Number should be greater than or equal 4")

**Example 2**

stub.rb
```ruby
validates :name, :presence => true
```

stubs_controller.rb
```ruby
conf.columns[:value].form_ui = :range
conf.columns[:value].options = {:min => -100, :max => 100, :step => 10}
```

result (note the `min`, `max` and `step` attributes):
```html

```
Browser doesn't allow to send form with empty required field.

![Spinbox control with validation of required text field](http://habrastorage.org/storage2/40e/8f8/a5e/40e8f8a5e87bf5db54a5b57ace1b5018.png "Browser don't allow to send form with empty 'name' field")

**Example 3**

stubs_controller.rb
```ruby
conf.columns[:precise].placeholder = "BE PRECISE!"
```

en.yml
```yaml
en:
activerecord:
placeholder:
stub:
name: 'Your name, bro'
occurs: 'Date, when it happens'
precise: 'Precised value'
```

result
![Fields with placeholders](http://habrastorage.org/storage2/91b/3cb/0c5/91b3cb0c50bd3967773089d35f9ee9d5.png "placeholders")

If pull request will be accepted, I'll update wiki.

What you think about it? Have I missed something?