mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Datepicker: Added ability to stop datepicker from beforeShow. Fixes #7602 - Ability to stop datepicker from appearing with beforeShow event handler.
This commit is contained in:
parent
7f812f8be9
commit
d146297356
@ -24,6 +24,39 @@ test('beforeShowDay-getDate', function() {
|
|||||||
inp.datepicker('hide');
|
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(){
|
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"));
|
var time = $.datepicker.formatDate("oo", new Date("2010/03/30 12:00:00 CDT"));
|
||||||
equals(time, "089");
|
equals(time, "089");
|
||||||
|
8
ui/jquery.ui.datepicker.js
vendored
8
ui/jquery.ui.datepicker.js
vendored
@ -625,6 +625,7 @@ $.extend(Datepicker.prototype, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/* Pop-up the date picker for a given input field.
|
/* 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
|
@param input element - the input field attached to the date picker or
|
||||||
event - if triggered by focus */
|
event - if triggered by focus */
|
||||||
_showDatepicker: function(input) {
|
_showDatepicker: function(input) {
|
||||||
@ -641,7 +642,12 @@ $.extend(Datepicker.prototype, {
|
|||||||
$.datepicker._curInst.dpDiv.stop(true, true);
|
$.datepicker._curInst.dpDiv.stop(true, true);
|
||||||
}
|
}
|
||||||
var beforeShow = $.datepicker._get(inst, 'beforeShow');
|
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;
|
inst.lastVal = null;
|
||||||
$.datepicker._lastInput = input;
|
$.datepicker._lastInput = input;
|
||||||
$.datepicker._setDateFromField(inst);
|
$.datepicker._setDateFromField(inst);
|
||||||
|
Loading…
Reference in New Issue
Block a user