Datebox has a number of public functions. They are:
Open the DateBox control
Close the DateBox control
Disable the DateBox control
Enable the DateBox control
Refresh the DateBox control
Retrieve the current date object
Set the current date object
Retrieve the last duration object
Set "opt" to "value"
Return a formatted date
Update the controls when min/max attributes have been changed
Datebox has a few standard init events. They are:
dateboxbeforecreate Note: this is called on *every* page if datebox is loaded, regardless if there are any datebox elements.
dateboxcreate Note: this happens dureing the init, before anything is set, and only on when datebox elements are found
dateboxaftercreate
Datebox also has a number of custom callback event types. They all fire the same master event, with an object payload. To catch:
$('element').bind('datebox', function (e, passed) { ... });
To override one of the action causeing methods, something like: (must happen before loading JQM and datebox to work)
$('document').bind('pagecreate', function() { $('element').bind('datebox', function(e, p) { if ( p.method === 'set' ) { e.stopImmediatePropagation() //DO SOMETHING// } }); });
{'method'} === open
{'method'} === close
{'method'} === set
{'value'} === value to place in input
{'date'} === the date object being used
{'method'} === doset
{'method'} === doclear
Note: Not used interaly.
{'method'} === dorefresh
Note: Not used interaly.
{'method'} === dooffset
{'amount'} === Amount of change (usually +/- 1)
{'type'} === Type of change ( 'y' = Year, 'm' = Month, 'd' = Date, 'h' = Hour, 'i' = Minute, 's' = Second, 'a' = Meridian )
{'method'} === enable
{'method'} === disable
{'method'} === refresh
{'method'} === clear
{'method'} === offset
{'amount'} === Amount of change (usually +/- 1)
{'type'} === Type of change ( 'y' = Year, 'm' = Month, 'd' = Date, 'h' = Hour, 'i' = Minute, 's' = Second, 'a' = Meridian )
Example code to disable datebox on close:
$('element').bind('datebox', function (e, passed) { if ( passed.method === 'close' ) { $('element').datebox('disable'); } });
Example to modify and set date without open (increment month by 2):
$('element').trigger('datebox', {'method':'dooffset', 'type':'m', 'amount':2}).trigger('datebox', {'method':'doset'});
Callbacks ('openCallback' and 'closeCallback') are simple to work with - a few interesting features:
Inside your function, initally, "this" will refer to the widget object
The first argument for the is always the date the control currently is set to.
The second argument and beyond can be set in 'openCallbackArgs' and 'closeCallbackArgs' respecitvly.
Fun toys inside the widget for your use:
The last duration set, in seconds
The current set date (object)
The currently generated HTML - this gets clobbered a lot.