Skip to content

Add HTML5 inputs #6359

Merged
merged 2 commits into from May 22, 2012

5 participants

@carlosgaldino

I started working on this since there were some other pull requests that were too old for a merge and the guys who created the pull requests didn't have time to update. Here they are: #5789 and #3826.

I didn't add input[type="time"] because #5715 is handling this.

Comments are welcome.

Thanks.

@rafaelfranca
Ruby on Rails member

Looks great. We need to upgrade the CHANGELOG and maybe add some entries in the form_builder guide.

@carlosgaldino

Updated. Let me know if there's anything else to do.

Thanks.

@rafaelfranca
Ruby on Rails member

I'll get more feedback.

cc/ @jeremy @josevalim

@jeremy jeremy commented on an outdated diff May 17, 2012
actionpack/CHANGELOG.md
@@ -1,5 +1,15 @@
## Rails 4.0.0 (unreleased) ##
+* Add `color_field` and `color_field_tag` helpers which render an `input[type="color"]` tag *Carlos Galdino*
+
+* Add `week_field` and `week_field_tag` helpers which render an `input[type="week"]` tag *Carlos Galdino*
+
+* Add `month_field` and `month_field_tag` helpers which render an `input[type="month"]` tag *Carlos Galdino*
+
+* Add `datetime_local_field` and `datetime_local_field_tag` helpers which render an `input[type="datetime-local"]` tag *Carlos Galdino*
+
+* Add `datetime_field` and `datetime_field_tag` helpers which render an `input[type="datetime"]` tag *Carlos Galdino*
+
@jeremy
Ruby on Rails member
jeremy added a note May 17, 2012

Please write one combined changelog entry describing the new input helpers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jeremy jeremy commented on the diff May 17, 2012
actionpack/lib/action_view/helpers/tags/color_field.rb
@@ -0,0 +1,8 @@
+module ActionView
+ module Helpers
+ module Tags
+ class ColorField < TextField #:nodoc:
@jeremy
Ruby on Rails member
jeremy added a note May 17, 2012

I didn't check the value for being valid because the email field also needs to be a valid email address and we don't check if the value passed is valid or not.

So, the question is, should Rails start checking the correctness of these fields or not?

http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-(type=email)

@jeremy
Ruby on Rails member
jeremy added a note May 17, 2012

I think we should. The HTML5 spec is pretty clear about the value sanitization algorithm for each field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jeremy jeremy and 1 other commented on an outdated diff May 17, 2012
...onpack/lib/action_view/helpers/tags/datetime_field.rb
@@ -0,0 +1,14 @@
+module ActionView
+ module Helpers
+ module Tags
+ class DatetimeField < TextField #:nodoc:
+ def render
+ options = @options.stringify_keys
+ options["value"] = @options.fetch("value") { value(object).try(:strftime, "%Y-%m-%dT%T.%L%z") }

Ok, I'll try to format the min and max attrs to be a valid date string like I did in this line but I don't think we should try to change/format the value of the step attr because the value should be expressed in seconds and I guess it'll be awkward to pass something different than a number to the step attr, like a DateTime instance or something.

What do you think?

@jeremy
Ruby on Rails member
jeremy added a note May 17, 2012

Sounds good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jeremy
Ruby on Rails member
jeremy commented May 17, 2012

Nice patch. How about separating this into one change for the color input and another for the datetime/month/etc inputs.

@josevalim
Ruby on Rails member

Jeremy Kemper - HTML 5 Forms Consultant.
The first of this kind. ❤️

@jeremy
Ruby on Rails member
jeremy commented May 17, 2012

@josevalim Opera 11 support, for great justice ❤️

@carlosgaldino

I updated the code. Please let me know if there's something to change.

@jeremy
Ruby on Rails member
jeremy commented May 21, 2012

Thanks @carlosgaldino. One last thing: please indent the methods under private.

carlosgaldino added some commits May 16, 2012
@carlosgaldino carlosgaldino Add HTML5 input[type="color"] helper 1ce4b5b
@carlosgaldino carlosgaldino Add several HTML5 input helpers
The input types added are:

- input[type="month"]

- input[type="week"]

- input[type="datetime"]

- input[type="datetime-local"]
b02d14a
@jeremy jeremy merged commit 65d2a60 into rails:master May 22, 2012
@gerwitz
gerwitz commented May 26, 2012

Any chance of a back port to 3.x?

@rafaelfranca
Ruby on Rails member

No. 3-2-stable is only for bug fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.