Created
September 30, 2010 10:37
-
-
Save tizoc/604378 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Bureaucrat | |
module Quickfields | |
def date(name, options = {}) | |
field name, DateField.new(options) | |
end | |
end | |
module Fields | |
class DateField < RegexField | |
DATE_RE = %r{^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$} | |
set_error :invalid, "Enter a valid date (YYYY-MM-DD)" | |
def initialize(options = {}) | |
super(DATE_RE, options) | |
end | |
def widget_attrs(widget) | |
{ :class => 'datepicker' } | |
end | |
def clean(value) | |
value = super(value) | |
Date.parse(value) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment