1 | <!doctype html>
|
---|
2 | <html lang="en">
|
---|
3 | <head>
|
---|
4 | <title>Datepicker Visual Test : Datepicker ticket #4071</title>
|
---|
5 | <link rel="stylesheet" href="../visual.css" type="text/css" />
|
---|
6 | <link rel="stylesheet" href="../../../themes/base/ui.all.css" type="text/css">
|
---|
7 | <script type="text/javascript" src="../../../jquery-1.4.1.js"></script>
|
---|
8 | <script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script>
|
---|
9 | <script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script>
|
---|
10 | <script type="text/javascript" src="../../../ui/jquery.ui.datepicker.js"></script>
|
---|
11 | <script type="text/javascript">
|
---|
12 |
|
---|
13 | function ValidatorHookupEvent(control, eventType, functionPrefix) {
|
---|
14 | var ev;
|
---|
15 | eval("ev = control." + eventType + ";");
|
---|
16 | if (typeof(ev) == "function") {
|
---|
17 | ev = ev.toString();
|
---|
18 | ev = ev.substring(ev.indexOf("{") + 1, ev.lastIndexOf("}"));
|
---|
19 | }
|
---|
20 | else {
|
---|
21 | ev = "";
|
---|
22 | }
|
---|
23 | var func;
|
---|
24 | if (navigator.appName.toLowerCase().indexOf('explorer') > -1) {
|
---|
25 | func = new Function(functionPrefix + " " + ev);
|
---|
26 | }
|
---|
27 | else {
|
---|
28 | func = new Function("event", functionPrefix + " " + ev);
|
---|
29 | }
|
---|
30 | eval("control." + eventType + " = func;");
|
---|
31 | }
|
---|
32 |
|
---|
33 | function HandleChange(event, boundBy) {
|
---|
34 | var boundBy = boundBy ? boundBy : '$(control).change(function(event){...})';
|
---|
35 | var type = event.type,
|
---|
36 | srcOrTarget = event.srcElement ? 'srcElement' : 'target',
|
---|
37 | tagName = event[srcOrTarget].tagName;
|
---|
38 | alert('[' + boundBy + ']\nevent.type: ' + type + '\nevent.' + srcOrTarget + '.tagName: ' + tagName);
|
---|
39 | }
|
---|
40 |
|
---|
41 | $(function() {
|
---|
42 | var control = $('#myInput')[0], eventType="onchange";
|
---|
43 |
|
---|
44 | $(control).datepicker();
|
---|
45 | $(control).change(HandleChange);
|
---|
46 | $('#changeButton').click(function() {
|
---|
47 | $(control).change();
|
---|
48 | });
|
---|
49 | $('#triggerButton').click(function() {
|
---|
50 | $(control).trigger('change');
|
---|
51 | });
|
---|
52 | $('#triggerHandlerButton').click(function() {
|
---|
53 | $(control).triggerHandler('change');
|
---|
54 | });
|
---|
55 | $('#fireEventButton').click(function() {
|
---|
56 | control.fireEvent('onchange');
|
---|
57 | });
|
---|
58 | if (!control.fireEvent) { $('#fireEventButton').remove(); }
|
---|
59 |
|
---|
60 | ValidatorHookupEvent(control, eventType, "HandleChange(event, 'eval(control.onchange = func)')");
|
---|
61 |
|
---|
62 | });
|
---|
63 | </script>
|
---|
64 | <style type="text/css">
|
---|
65 | button { display: block; }
|
---|
66 | </style>
|
---|
67 | </head>
|
---|
68 | <body>
|
---|
69 |
|
---|
70 | <h1 class="ui-widget-header"><a href="http://dev.jqueryui.com/ticket/4071">#4071 - 'length' is null or not an object</a></h1>
|
---|
71 |
|
---|
72 | <h2>Summary</h2>
|
---|
73 | In Internet Explorer, when a event such as click on one element causes a change event on another element to trigger programmatically, any change event handler that was bound to that second element through onchange gets the click event instead of the change event.
|
---|
74 |
|
---|
75 | <h2>Steps to reproduce</h2>
|
---|
76 | <p>
|
---|
77 | To demonstrate the issue, do one of the following:
|
---|
78 | </p>
|
---|
79 | <ul>
|
---|
80 | <li>Click the input to open the Datepicker, then select a date</li>
|
---|
81 | <li>Or press a number in the text field and blur</li>
|
---|
82 | <li>Or click a button below</li>
|
---|
83 | </ul>
|
---|
84 | <p>
|
---|
85 | Each will trigger change on the text input. The input has a handler bound in three different ways. Notice the difference when pressing a number in the input and bluring versus either selecting a date or pressing one of the first three buttons. In Internet Explorer, when the issue is present, 2 out of the three event objects are of type 'click' instead of 'change' and have the wrong corresponding srcElement/target when the datepicker or one of the first three buttons are clicked.
|
---|
86 | </p>
|
---|
87 |
|
---|
88 | <input type="text" id="myInput" onchange="HandleChange(event, '<input onchange=\'...\' />')" />
|
---|
89 | <button id="changeButton">Click to trigger change event via $(control).change();</button>
|
---|
90 | <button id="triggerButton">Click to trigger change event via $(control).trigger('change');</button>
|
---|
91 | <button id="triggerHandlerButton">Click to trigger change event via $(control).triggerHandler('change');</button>
|
---|
92 | <button id="fireEventButton">Click to fire change event via control.fireEvent('onchange');</button>
|
---|
93 |
|
---|
94 | </body>
|
---|
95 | </html>
|
---|