|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>The valuechange Event</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>The valuechange Event</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<p>The <code>event-valuechange</code> module adds a "valuechange" event that fires |
|
|
32 |
when the <code>value</code> property of an <code><input></code> or <code><textarea></code> element changes as |
|
|
33 |
the result of a keystroke, mouse operation, or input method editor (IME) |
|
|
34 |
input event.</p> |
|
|
35 |
</div> |
|
|
36 |
|
|
|
37 |
<h2 id="whats-the-problem">What's the problem?</h2> |
|
|
38 |
|
|
|
39 |
<p>The input related events provided by browsers don't cleanly address the |
|
|
40 |
variety of ways users can modify an <code><input></code> or <code><textarea></code>'s |
|
|
41 |
<code>value</code>. For example, users might change an input value by:</p> |
|
|
42 |
|
|
|
43 |
<ul> |
|
|
44 |
<li>typing a simple character</li> |
|
|
45 |
<li>typing a multi-stroke character</li> |
|
|
46 |
<li> |
|
|
47 |
using an <a href="http://en.wikipedia.org/wiki/Input_method">Input |
|
|
48 |
Method Editor</a> |
|
|
49 |
</li> |
|
|
50 |
<li>cutting from or pasting into the value with <code>Ctrl+X</code> or <code>Cmd+V</code></li> |
|
|
51 |
<li>cutting or pasting with a keyboard-summoned context menu</li> |
|
|
52 |
<li>cutting or pasting from the right-click context menu.</li> |
|
|
53 |
</ul> |
|
|
54 |
|
|
|
55 |
<p>The ideal change event would fire when the value becomes <em>something it |
|
|
56 |
wasn't a moment ago</em>.</p> |
|
|
57 |
|
|
|
58 |
<p>The <code>valuechange</code> event provides more reliable input notifications than |
|
|
59 |
native events like <code>oninput</code> and <code>textInput</code>, particularly with changes that |
|
|
60 |
result from multiple-keystroke IME input.</p> |
|
|
61 |
|
|
|
62 |
<pre class="code prettyprint">commentTextarea.on('valuechange', updateLivePreview);</pre> |
|
|
63 |
|
|
|
64 |
|
|
|
65 |
<h2 id="how-it-works">How it works</h2> |
|
|
66 |
|
|
|
67 |
<p><code>valuechange</code> subscriptions monitor the element's value using a variety of |
|
|
68 |
mechanisms including subscriptions to <code>focus</code> and various keyboard events, and a |
|
|
69 |
poll to catch the stragglers. It seems like a lot of work, but it's the only |
|
|
70 |
way to be sure.</p> |
|
|
71 |
|
|
|
72 |
<p>Polling is only active when the element is focused, and only one element is |
|
|
73 |
polled at a time, so the performance of your app should not be impacted.</p> |
|
|
74 |
|
|
|
75 |
<h2 id="caveats">Caveats</h2> |
|
|
76 |
|
|
|
77 |
<ul> |
|
|
78 |
<li> |
|
|
79 |
<p> |
|
|
80 |
<code>valuechange</code> only supports subscriptions on <code><input></code> and |
|
|
81 |
<code><textarea></code> elements, although it doesn't prevent you from subscribing |
|
|
82 |
on other types of elements. If you subscribe on a different type of element |
|
|
83 |
and stuff breaks, you were warned. |
|
|
84 |
</p> |
|
|
85 |
</li> |
|
|
86 |
|
|
|
87 |
<li> |
|
|
88 |
<p> |
|
|
89 |
<code>valuechange</code> does not capture <code>value</code> updates done in JavaScript |
|
|
90 |
<em>unless the input is currently focused and polling</em>. It's meant |
|
|
91 |
to capture changes made by the user, not by other code. So: |
|
|
92 |
<code>node.set('value', 'probably will not trigger valuechange');</code> |
|
|
93 |
</p> |
|
|
94 |
</li> |
|
|
95 |
</ul> |
|
|
96 |
</div> |
|
|
97 |
</div> |
|
|
98 |
</div> |
|
|
99 |
|
|
|
100 |
<div class="yui3-u-1-4"> |
|
|
101 |
<div class="sidebar"> |
|
|
102 |
|
|
|
103 |
<div id="toc" class="sidebox"> |
|
|
104 |
<div class="hd"> |
|
|
105 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
106 |
</div> |
|
|
107 |
|
|
|
108 |
<div class="bd"> |
|
|
109 |
<ul class="toc"> |
|
|
110 |
<li> |
|
|
111 |
<a href="#whats-the-problem">What's the problem?</a> |
|
|
112 |
</li> |
|
|
113 |
<li> |
|
|
114 |
<a href="#how-it-works">How it works</a> |
|
|
115 |
</li> |
|
|
116 |
<li> |
|
|
117 |
<a href="#caveats">Caveats</a> |
|
|
118 |
</li> |
|
|
119 |
</ul> |
|
|
120 |
</div> |
|
|
121 |
</div> |
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
<div class="sidebox"> |
|
|
126 |
<div class="hd"> |
|
|
127 |
<h2 class="no-toc">Examples</h2> |
|
|
128 |
</div> |
|
|
129 |
|
|
|
130 |
<div class="bd"> |
|
|
131 |
<ul class="examples"> |
|
|
132 |
|
|
|
133 |
|
|
|
134 |
<li data-description="Use the Event Utility to attach simple DOM event handlers."> |
|
|
135 |
<a href="basic-example.html">Simple DOM Events</a> |
|
|
136 |
</li> |
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
<li data-description="Using the synthetic event API to create a DOM event that fires in response to arrow keys being pressed."> |
|
|
141 |
<a href="synth-example.html">Creating an Arrow Event for DOM Subscription</a> |
|
|
142 |
</li> |
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
<li data-description="Supporting cross-device swipe gestures, using the event-move gesture events"> |
|
|
147 |
<a href="swipe-example.html">Supporting A Swipe Left Gesture</a> |
|
|
148 |
</li> |
|
|
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
</ul> |
|
|
162 |
</div> |
|
|
163 |
</div> |
|
|
164 |
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
<div class="sidebox"> |
|
|
168 |
<div class="hd"> |
|
|
169 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
170 |
</div> |
|
|
171 |
|
|
|
172 |
<div class="bd"> |
|
|
173 |
<ul class="examples"> |
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
<li data-description="Creating an accessible menu button using the Focus Manager Node Plugin, Event's delegation support and mouseenter event, along with the Overlay widget and Node's support for the WAI-ARIA Roles and States."> |
|
|
183 |
<a href="../node-focusmanager/node-focusmanager-button.html">Accessible Menu Button</a> |
|
|
184 |
</li> |
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
|
188 |
<li data-description="Shows how to extend the base widget class, to create your own Widgets."> |
|
|
189 |
<a href="../widget/widget-extend.html">Extending the Base Widget Class</a> |
|
|
190 |
</li> |
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
<li data-description="Example Photo Browser application."> |
|
|
195 |
<a href="../dd/photo-browser.html">Photo Browser</a> |
|
|
196 |
</li> |
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation."> |
|
|
201 |
<a href="../dd/portal-drag.html">Portal Style Example</a> |
|
|
202 |
</li> |
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
<li data-description="Use IO to request data over HTTP."> |
|
|
207 |
<a href="../io/get.html">HTTP GET to request data</a> |
|
|
208 |
</li> |
|
|
209 |
|
|
|
210 |
|
|
|
211 |
</ul> |
|
|
212 |
</div> |
|
|
213 |
</div> |
|
|
214 |
|
|
|
215 |
</div> |
|
|
216 |
</div> |
|
|
217 |
</div> |
|
|
218 |
</div> |
|
|
219 |
|
|
|
220 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
221 |
<script>prettyPrint();</script> |
|
|
222 |
|
|
|
223 |
<script> |
|
|
224 |
YUI.Env.Tests = { |
|
|
225 |
examples: [], |
|
|
226 |
project: '../assets', |
|
|
227 |
assets: '../assets/event', |
|
|
228 |
name: 'event', |
|
|
229 |
title: 'The valuechange Event', |
|
|
230 |
newWindow: '', |
|
|
231 |
auto: false |
|
|
232 |
}; |
|
|
233 |
YUI.Env.Tests.examples.push('basic-example'); |
|
|
234 |
YUI.Env.Tests.examples.push('synth-example'); |
|
|
235 |
YUI.Env.Tests.examples.push('swipe-example'); |
|
|
236 |
YUI.Env.Tests.examples.push('node-focusmanager-button'); |
|
|
237 |
YUI.Env.Tests.examples.push('widget-extend'); |
|
|
238 |
YUI.Env.Tests.examples.push('photo-browser'); |
|
|
239 |
YUI.Env.Tests.examples.push('portal-drag'); |
|
|
240 |
YUI.Env.Tests.examples.push('get'); |
|
|
241 |
|
|
|
242 |
</script> |
|
|
243 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
</body> |
|
|
248 |
</html> |