Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message if Datepicker calendar is clicked after input is removed from DOM? #2127

Open
alexdowad opened this issue Oct 28, 2022 · 3 comments

Comments

@alexdowad
Copy link

It can happen that after a non-inline Datepicker is opened, the <input> which the datepicker is "attached to" is removed from the DOM. When the user then clicks on the Datepicker calendar, an exception will be thrown with the message: "Missing instance data for this datepicker".

This is the relevant bit of code:

	/* Adjust one of the date sub-fields. */
	_adjustDate: function( id, offset, period ) {
		var target = $( id ),
			inst = this._getInst( target[ 0 ] );

Note that after retrieving target with $( id ), it is used right away without checking whether target.length > 0 or not. I would like to suggest it would be a good idea to make that check. If target is indeed empty, then an exception could be thrown with a more informative message.

(A web search reveals a lot of questions about the Missing instance data message; apparently it is challenging for a lot of users to understand what this message indicates.)

@mgol
Copy link
Member

mgol commented Nov 2, 2022

Thanks for the report. Does the issue you describe exist when jQuery UI 1.12.1 is used or only with jQuery UI 1.13.0 or newer?

@mgol mgol added the Needs info label Nov 2, 2022
@alexdowad
Copy link
Author

@mgol Thanks for the question. I am not available to delve into this issue further, but the relevant code is still there on the current main branch:

/* Adjust one of the date sub-fields. */
_adjustDate: function( id, offset, period ) {
var target = $( id ),
inst = this._getInst( target[ 0 ] );

@mgol
Copy link
Member

mgol commented Nov 3, 2022

Thanks, but we can't do much without a test case, especially that the UI team has limited resources now. See the project status at https://blog.jqueryui.com/2021/10/jquery-maintainers-update-and-transition-jquery-ui-as-part-of-overall-modernization-efforts/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants