# Popup Calendar and DateBoxEngine and Change Made

**URL:** <https://www.ruby-forum.com/t/popup-calendar-and-dateboxengine-and-change-made/100668>\
**Category:** Rails\
**Created:** [July 31, 2006, 9:35am UTC](https://www.ruby-forum.com/t/popup-calendar-and-dateboxengine-and-change-made/100668 "2006-07-31T09:35:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike343](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike343](https://www.ruby-forum.com/u/mike343)\
**Post date:** [July 31, 2006, 9:35am UTC](https://www.ruby-forum.com/t/popup-calendar-and-dateboxengine-and-change-made/100668/1 "2006-07-31T09:35:57Z")

</div>

Community,

I have been putting off implementing a Date selector for too long.  
Tonight, I finally put it in. I made the choice to go with the datebox  
engine.

Once I got it installed and working, I realized I didn’t like the way it  
required you to call it. Example:

\<% @dateField = model.date %\>  
\<%= date\_box %\>

or…

\<% @dateField1 = model.date %\>  
\<%= date\_box(@dateField1)

which then requires you to trap on these fields during the update/create  
actions of the controller. This didn’t seem correct. I wanted multiple  
dates on a page and I wanted an easy way to get the calendar to popup.  
Here is what I wanted:

\<%= date\_box( ‘model\_name’, ‘field\_name\_for\_date1’ ) %\>  
\<%= date\_box( ‘model\_name’, ‘field\_name\_for\_date2’ ) %\>

etc…

which is consisent with other form helpers (minus the options hash).  
Therefore, I made a minor change to the engine code. I made this change  
to meet my needs and hopefully others will get some use of it too. It  
changes the definition and I didn’t touch every aspect of the engine -  
only the piece that I was interested in. Here it is for anyone else who  
wants to work with the date\_box like I wanted to.

If you have any questions or need clarification then let me know.

Thanks,

Michael

Modified file:  
vendor/plugins/datebox\_engine/app/helpers/application\_helper.rb:

Replace existing date\_box method with the following:

```
def date_box(object_name, method)
	calendar_ref = object_name + '_' + method
	<<-EOL

```

- #{engine\_image('icon-help.gif', :engine =\> 'datebox', :alt =\> 'Help', :id =\> calendar\_ref + 'Help' ) }
- #{text\_field object\_name, method, { :onChange =\> "magicDate(id);", :onFocus =\> "if (this.className != 'error') this.select()"} }
- #{engine\_image('icon-calendar.gif', :engine =\> 'datebox', :alt =\> 'Calendar', :id =\> calendar\_ref + 'Button', :style =\> 'cursor: pointer;' ) }

```
</ul>
<div style="clear:both"></div>
<div id="#{calendar_ref}Msg"><script 

```

type=“text/javascript”\>document.write(calendarFormatString);

  
 EOL end

---

<div class="post-metadata">

**Author:** ![mike343](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike343](https://www.ruby-forum.com/u/mike343)\
**Post date:** [August 2, 2006, 6:03am UTC](https://www.ruby-forum.com/t/popup-calendar-and-dateboxengine-and-change-made/100668/2 "2006-08-02T06:03:12Z")

</div>

Turns out a few people have tried to use the code above and had problems  
with the final result. It was pretty late so perhaps I pasted a version  
that had a slight bug in it! ☹ Anyway, here is something that has  
worked for everyone who has tried it. I did make a few changes to the  
layout so it is slightly different than the original version but more to  
my liking.

If this gives you problems then please email me at codeslush at yahoo  
dot com.

Regards,

Michael

def date\_box(object\_name, method)  
calendar\_ref = object\_name + ‘\_’ + method  
\<\<-EOL

  

  
- #{text\_field object\_name, method, { :onChange =\>  
“magicDate(id);”, :onFocus =\> “if (this.className != ‘error’)  
this.select()”} }
  
- #{engine\_image(‘icon-calendar.gif’, :engine =\> ‘datebox’, :alt =\>  
‘Calendar’, :id =\> calendar\_ref + ‘Button’, :style =\> ‘cursor: pointer;’  
) }
  
- #{engine\_image(‘icon-help.gif’, :engine =\> ‘datebox’, :alt =\>  
‘Help’, :id =\> calendar\_ref + ‘Help’ ) }
  

  

  

  
  

  
EOL  
end

---

<div class="post-metadata">

**Author:** ![mike343](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike343](https://www.ruby-forum.com/u/mike343)\
**Post date:** [August 9, 2006, 10:21am UTC](https://www.ruby-forum.com/t/popup-calendar-and-dateboxengine-and-change-made/100668/3 "2006-08-09T10:21:54Z")

</div>

i just wanted to thank you, i’ve been stumbling with this from a few  
days ago, almost got it to work, but it was somewhat buggy, im not too  
good at JS, your implementation works great!

---

<div class="post-metadata">

**Author:** ![mike343](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike343](https://www.ruby-forum.com/u/mike343)\
**Post date:** [August 9, 2006, 5:05pm UTC](https://www.ruby-forum.com/t/popup-calendar-and-dateboxengine-and-change-made/100668/4 "2006-08-09T17:05:13Z")

</div>

Pablo O. wrote:

> i just wanted to thank you, i’ve been stumbling with this from a few  
> days ago, almost got it to work, but it was somewhat buggy, im not too  
> good at JS, your implementation works great!

Thank you. I wrote the author an email and sent him the changes as well  
but I didn’t get any feedback - so I don’t know if he will add it to the  
code base or not. Several people have been able to use this now and I  
hope that he will consider adding the change. Either way, I’m glad it  
was of help to you!

Regards,

Michael

---

<div class="post-metadata">

**Author:** ![mike343](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike343](https://www.ruby-forum.com/u/mike343)\
**Post date:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/popup-calendar-and-dateboxengine-and-change-made/100668/5 "2006-08-15T14:19:24Z")

</div>

Did this message get through? The reply afterwards doesn’t appear to  
make  
any mention of it.

On 8/11/06, Nathaniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> -NSHB
> 
> > * * *
> 
> Nathaniel B.
> 
> Inimit Innovations Inc.  
> [http://inimit.com](http://inimit.com)

–  
Kind regards,

Nathaniel B.

Inimit Innovations Inc.  
[http://inimit.com](http://inimit.com)

---

<div class="post-metadata">

**Author:** ![mike343](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike343](https://www.ruby-forum.com/u/mike343)\
**Post date:** [August 15, 2006, 2:18pm UTC](https://www.ruby-forum.com/t/popup-calendar-and-dateboxengine-and-change-made/100668/6 "2006-08-15T14:18:53Z")

</div>

Hey Michael,

The patch looks nice, and I do appreciate your diff.

Any chance you able to post it to [http://dev.toolbocks.com](http://dev.toolbocks.com) so I can be  
sure  
it gets included with the next version?

I promise, one is coming soon!

-NSHB

On 8/9/06, Pablo O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Kind regards,

Nathaniel B.

Inimit Innovations Inc.  
[http://inimit.com](http://inimit.com)
