Michael Modica
2006-Jul-31 07:36 UTC
[Rails] Popup Calendar and DateBoxEngine and Change Made ...
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 <div id="dateBox"> <ul> <li>#{engine_image(''icon-help.gif'', :engine => ''datebox'', :alt => ''Help'', :id => calendar_ref + ''Help'' ) }</li> <li>#{text_field object_name, method, { :onChange => "magicDate(id);", :onFocus => "if (this.className != ''error'') this.select()"} }</li> <li>#{engine_image(''icon-calendar.gif'', :engine => ''datebox'', :alt => ''Calendar'', :id => calendar_ref + ''Button'', :style => ''cursor: pointer;'' ) }</li> </ul> <div style="clear:both"></div> <div id="#{calendar_ref}Msg"><script type="text/javascript">document.write(calendarFormatString); </script></div> <script type="text/javascript"> Calendar.setup({ inputField : "#{calendar_ref}", // id of the input field ifFormat : calendarIfFormat, // format of the input field button : "#{calendar_ref}Button", // trigger for the calendar (button ID) help : "#{calendar_ref}Help", // trigger for the help menu align : "Bl", // alignment (defaults to "Bl") singleClick : true }); document.getElementById("#{calendar_ref}").onkeydown = dateBoxKeyListener </script> </div> EOL end -- Posted via http://www.ruby-forum.com/.
Michael Modica
2006-Aug-02 04:03 UTC
[Rails] Re: Popup Calendar and DateBoxEngine and Change Made ...
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 <div id="dateBox"> <ul> <li>#{text_field object_name, method, { :onChange => "magicDate(id);", :onFocus => "if (this.className != ''error'') this.select()"} }</li> <li>#{engine_image(''icon-calendar.gif'', :engine => ''datebox'', :alt => ''Calendar'', :id => calendar_ref + ''Button'', :style => ''cursor: pointer;'' ) }</li> <li>#{engine_image(''icon-help.gif'', :engine => ''datebox'', :alt => ''Help'', :id => calendar_ref + ''Help'' ) }</li> </ul> <div style="clear:both"></div> <div style="display:none" id="#{calendar_ref}Msg"><script type="text/javascript">document.write(calendarFormatString); </script></div> <script type="text/javascript"> Calendar.setup({ inputField : "#{calendar_ref}", // id of the input field ifFormat : calendarIfFormat, // format of the input field button : "#{calendar_ref}Button", // trigger for the calendar (button ID) help : "#{calendar_ref}Help", // trigger for the help menu align : "Bl", // alignment (defaults to "Bl") singleClick : true }); document.getElementById("#{calendar_ref}").onkeydown = dateBoxKeyListener </script> </div> EOL end -- Posted via http://www.ruby-forum.com/.
Pablo Ortiz
2006-Aug-09 08:24 UTC
[Rails] Re: Popup Calendar and DateBoxEngine and Change Made ...
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! -- Posted via http://www.ruby-forum.com/.
Michael Modica
2006-Aug-09 15:12 UTC
[Rails] Re: Popup Calendar and DateBoxEngine and Change Made ...
Pablo Ortiz 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 -- Posted via http://www.ruby-forum.com/.
Nathaniel Brown
2006-Aug-11 07:39 UTC
[Rails] Re: Popup Calendar and DateBoxEngine and Change Made ...
Hey Michael, The patch looks nice, and I do appreciate your diff. Any chance you able to post it to 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 Ortiz <pablasso@gmail.com> 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! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Kind regards, Nathaniel Brown Inimit Innovations Inc. http://inimit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060811/ae9bd3d0/attachment.html
Nathaniel Brown
2006-Aug-13 23:28 UTC
[Rails] Re: Popup Calendar and DateBoxEngine and Change Made ...
Did this message get through? The reply afterwards doesn''t appear to make any mention of it. On 8/11/06, Nathaniel Brown <nshb@inimit.com> wrote:> > Hey Michael, > > The patch looks nice, and I do appreciate your diff. > > Any chance you able to post it to 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 Ortiz <pablasso@gmail.com> 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! > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > -- > Kind regards, > > Nathaniel Brown > > Inimit Innovations Inc. > http://inimit.com >-- Kind regards, Nathaniel Brown Inimit Innovations Inc. http://inimit.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060813/08ce22a8/attachment.html
Justin Forder
2006-Aug-14 00:28 UTC
Mail delays (was Re: [Rails] Re: Popup Calendar and DateBoxEngine and Change Made ...)
Nathaniel Brown wrote:> Did this message get through? The reply afterwards doesn''t appear to make > any mention of it.It took over two days to get through to me. I''ve been watching a lot of email threads without seeing the original message until long after the follow-ups have come through - one just arrived after three days! DHH posted that the mail and Trac server has been overloaded, and a new server is about to be dedicated to running Trac and the repository. http://weblog.rubyonrails.org/2006/8/10/new-dedicated-trac-server-on-the-way With luck, the mail situation will improve. We have had situations like this before, and they have been fixed effectively. regards (fingers crossed) Justin> > On 8/11/06, Nathaniel Brown <nshb@inimit.com> wrote: >> >> Hey Michael, >> >> The patch looks nice, and I do appreciate your diff. >> >> Any chance you able to post it to 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 Ortiz <pablasso@gmail.com> 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!