Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Ticket 7602: Stop datepicker from appearing with beforeShow event handler #378

Closed
wants to merge 2 commits into from

3 participants

@joekarl

Small patch to allow stopping the datepicker from a beforeShow event handler.
Just checking to see if the return from the beforeShow handler is === false.
If it is === false then we return the same way as if the datepicker is disabled.

Also added demo page for this functionality.

$('#datepicker').datepicker({
    beforeShow: function(){
        return false; //will make datepicker not show
    }
});
Karl Kirch Added ability to stop datepicker from beforeShow
Small patch to allow stopping the datepicker from a beforeShow event handler.
Just checking to see if the return from the beforeShow handler is === false.
If it is === false then we return the same way as if the datepicker is disabled.
c18edae
@gnarf
Owner

You're trying to make the beforeShow event cancelable basically right? Can you perhaps make a ticket for this in the bug tracker? http://jqbug.com/ui/new

@scottgonzalez

This needs a unit test and the demo should be removed.

Karl Kirch Added unit test for cancel show in beforeShow
Removed uneeded demo
Added test cases for before show returning false, truthy, and true
9d3f53b
@joekarl

Demo removed and unit tests added.

@joekarl

Unit test is in tests/unit/datepicker/datepicker_tickets.js

Ticket 7602: Stop datepicker from appearing with beforeShow event handler (0, 3, 3)

@scottgonzalez

Thanks, landed in d146297.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 6, 2011
  1. Added ability to stop datepicker from beforeShow

    Karl Kirch authored
    Small patch to allow stopping the datepicker from a beforeShow event handler.
    Just checking to see if the return from the beforeShow handler is === false.
    If it is === false then we return the same way as if the datepicker is disabled.
Commits on Aug 3, 2011
  1. Added unit test for cancel show in beforeShow

    Karl Kirch authored
    Removed uneeded demo
    Added test cases for before show returning false, truthy, and true
This page is out of date. Refresh to see the latest.
View
33 tests/unit/datepicker/datepicker_tickets.js
@@ -24,6 +24,39 @@ test('beforeShowDay-getDate', function() {
inp.datepicker('hide');
});
+test('Ticket 7602: Stop datepicker from appearing with beforeShow event handler', function(){
+ var inp = init('#inp',{
+ beforeShow: function(){
+ return false;
+ }
+ });
+ var dp = $('#ui-datepicker-div');
+ inp.datepicker('show');
+ equals(dp.css('display'), 'none',"beforeShow returns false");
+ inp.datepicker('destroy');
+
+ inp = init('#inp',{
+ beforeShow: function(){
+ }
+ });
+ dp = $('#ui-datepicker-div');
+ inp.datepicker('show');
+ equal(dp.css('display'), 'block',"beforeShow returns nothing");
+ inp.datepicker('hide');
+ inp.datepicker('destroy');
+
+ inp = init('#inp',{
+ beforeShow: function(){
+ return true;
+ }
+ });
+ dp = $('#ui-datepicker-div');
+ inp.datepicker('show');
+ equal(dp.css('display'), 'block',"beforeShow returns true");
+ inp.datepicker('hide');
+ inp.datepicker('destroy');
+});
+
test('Ticket 6827: formatDate day of year calculation is wrong during day lights savings time', function(){
var time = $.datepicker.formatDate("oo", new Date("2010/03/30 12:00:00 CDT"));
equals(time, "089");
View
8 ui/jquery.ui.datepicker.js
@@ -623,6 +623,7 @@ $.extend(Datepicker.prototype, {
},
/* Pop-up the date picker for a given input field.
+ If false returned from beforeShow event handler do not show.
@param input element - the input field attached to the date picker or
event - if triggered by focus */
_showDatepicker: function(input) {
@@ -639,7 +640,12 @@ $.extend(Datepicker.prototype, {
$.datepicker._curInst.dpDiv.stop(true, true);
}
var beforeShow = $.datepicker._get(inst, 'beforeShow');
- extendRemove(inst.settings, (beforeShow ? beforeShow.apply(input, [input, inst]) : {}));
+ var beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {};
+ if(beforeShowSettings === false){
+ //false
+ return;
+ }
+ extendRemove(inst.settings, beforeShowSettings);
inst.lastVal = null;
$.datepicker._lastInput = input;
$.datepicker._setDateFromField(inst);
Something went wrong with that request. Please try again.