# Text field as date selector (not comboboxes) =\> how to creat

**URL:** <https://www.ruby-forum.com/t/text-field-as-date-selector-not-comboboxes-how-to-creat/81702>\
**Category:** Rails\
**Created:** [January 11, 2007, 3:08pm UTC](https://www.ruby-forum.com/t/text-field-as-date-selector-not-comboboxes-how-to-creat/81702 "2007-01-11T15:08:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 11, 2007, 3:08pm UTC](https://www.ruby-forum.com/t/text-field-as-date-selector-not-comboboxes-how-to-creat/81702/1 "2007-01-11T15:08:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 11, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/text-field-as-date-selector-not-comboboxes-how-to-creat/81702/2 "2007-01-11T23:55:46Z")

</div>

Check out the DateBocks plugin at [http://datebocks.inimit.com/](http://datebocks.inimit.com/) 🙂

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 15, 2007, 4:35pm UTC](https://www.ruby-forum.com/t/text-field-as-date-selector-not-comboboxes-how-to-creat/81702/3 "2007-01-15T16:35:00Z")

</div>

removed\_email\_address@domain.invalid 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 M.  
Informatika Mihelac, Bojan M. s.p. | [www.informatikamihelac.com](http://www.informatikamihelac.com)  
 → tools, scripts, tricks from our code lab: [http://source.mihelac.org](http://source.mihelac.org)
