Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How might you unobtrusively enhance the jQuery Datepicker class?

Tags:

You can pass special strings into jQuery's Datepicker class setDate() method like "+7" which will be translated into "7 days from today":

http://docs.jquery.com/UI/Datepicker#method-setDate

But you can't get that "+7" back out. When you call getDate() you get the calculated resulting date.

I have a use case where I need to pull out the special string "+7" for propagation. One chunk of code is passing a special string into the Datepicker and passing the Datepicker over to another chunk of code which pulls out the date, but the latter sometimes needs to know the special string rather than the calculated date.

So I need to enhance the Datepicker tool to (a) store the special code internally and (b) expose it via a method like getOriginallyPassedInDate() or some such.

I'm not a jQuery/Javascript ninja so I could really use some guidance on how I might preferably-unobtrusively add the necessary functionality to the Datepicker class, the way you might monkey-patch an object in Ruby I'm guessing.

like image 513
Teflon Ted Avatar asked Mar 15 '10 14:03

Teflon Ted


1 Answers

Check out Paul Irish's post on Duck Punching with Jquery

like image 149
PetersenDidIt Avatar answered Sep 28 '22 07:09

PetersenDidIt