Forum: Ruby on Rails text field as date selector (not comboboxes) => how to creat

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4900d0b180e9b9070a14fe78a698c0a4?d=identicon&s=25 andimeier@gmx.net (Guest)
on 2007-01-11 15:08
(Received via mailing list)
Having to set 6 comboboxes just to enter a date/time is simply overkill
to me. I prefer a simple text field where I can (e.g. for date input
fields) input strings like
  2007-12-02
  +3  (remark: means the date of 3 days after today)
  12-05  (remark: will be completed with the current year)

I already have implemented the functionality of parsing these dates,
but now I am not sure how to integrate it into the Rails framework
(plugin mechanism?).

Does anybody know how to do this? Is there some documentation about
writing own form helpers like this?
F5c118aaeb5bb7162db613a37e595be8?d=identicon&s=25 Mick Sharpe (micksharpe)
on 2007-01-11 23:55
Check out the DateBocks plugin at http://datebocks.inimit.com/ :)
866edcb271e88be4bfd935eea7947730?d=identicon&s=25 Bojan Mihelac (Guest)
on 2007-01-15 16:35
(Received via mailing list)
andimeier@gmx.net wrote:
>
> Does anybody know how to do this? Is there some documentation about
> writing own form helpers like this?
>
>
> >
>
>
>

I use this to display and parse european dates (dd.mm.yyyy).


module ActionView # :nodoc:
   module Helpers # :nodoc:
     class InstanceTag
       def to_date_select_tag(options = {})
         #to_input_field_tag('text', {'size'=>'10'}.merge(options))
         options = options.stringify_keys
         options["size"] ||= options["maxlength"] ||
DEFAULT_FIELD_OPTIONS["size"]
         options = DEFAULT_FIELD_OPTIONS.merge(options)
         options["type"] = 'text'
         options["value"] ||=
value.to_formatted_s(options["date_format"] || :input_format) if
value.kind_of?(Date)
         add_default_name_and_id(options)
         tag("input", options)
       end
     end
   end
end

require ('parsedate')
module ParseDate
   class << self
     alias_method :old_parsedate, :parsedate unless
method_defined?(:old_parsedate)
   end

   def self.parsedate(str)
     match = /(\d{1,2})\.(\d{1,2})\.(\d{2,4})\.?/.match(str)
     return ParseDate.old_parsedate(str) unless match
     [match[3].to_i, match[2].to_i, match[1].to_i, nil, nil, nil, nil,
nil]
   end
end

--
Bojan Mihelac
Informatika Mihelac, Bojan Mihelac s.p.  |  www.informatikamihelac.com
-> tools, scripts, tricks from our code lab: http://source.mihelac.org
This topic is locked and can not be replied to.