mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Datepicker: prevent datepicker initialization on empty jquery collection and add unit test. Fixed #6976 - datepicker creates extra dom element with empty object
This commit is contained in:
parent
6c3477e12e
commit
5c3dc7d48a
@ -47,6 +47,11 @@ module("datepicker: core", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( "widget method - empty collection", function() {
|
||||||
|
$( "#nonExist" ).datepicker(); // should create nothing
|
||||||
|
ok( !$( "#ui-datepicker-div" ).length, "Non init on empty collection" );
|
||||||
|
});
|
||||||
|
|
||||||
test("widget method", function() {
|
test("widget method", function() {
|
||||||
var actual = $("#inp").datepicker().datepicker("widget")[0];
|
var actual = $("#inp").datepicker().datepicker("widget")[0];
|
||||||
same($("body > #ui-datepicker-div:last-child")[0], actual);
|
same($("body > #ui-datepicker-div:last-child")[0], actual);
|
||||||
|
5
ui/jquery.ui.datepicker.js
vendored
5
ui/jquery.ui.datepicker.js
vendored
@ -1727,6 +1727,11 @@ function isArray(a) {
|
|||||||
@return jQuery object */
|
@return jQuery object */
|
||||||
$.fn.datepicker = function(options){
|
$.fn.datepicker = function(options){
|
||||||
|
|
||||||
|
/* Verify an empty collection wasn't passed - Fixes #6976 */
|
||||||
|
if ( !this.length ) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialise the date picker. */
|
/* Initialise the date picker. */
|
||||||
if (!$.datepicker.initialized) {
|
if (!$.datepicker.initialized) {
|
||||||
$(document).mousedown($.datepicker._checkExternalClick).
|
$(document).mousedown($.datepicker._checkExternalClick).
|
||||||
|
Loading…
Reference in New Issue
Block a user