jquery / jquery/jquery-ui

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

Open
#2,127 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs info
Dominant language
JavaScript
Stars
11.3k
Forks
5.2k
PR merge metrics
No merged PRs in 30d

Description

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.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the _adjustDate entry point shown in the issue and reproduce the non-inline Datepicker case after its attached input is removed from the DOM. Confirm the empty target is handled without the current "Missing instance data for this datepicker" exception, and that the resulting error is more informative.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, jquery
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.