<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The valuechange Event</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="../../build/yui/yui-min.js"></script>
</head>
<body>
<!--
<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>
-->
<div id="doc">
<div id="hd">
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
</div>
<a href="#toc" class="jump">Jump to Table of Contents</a>
<h1>The valuechange Event</h1>
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
<div class="content"><div class="intro">
<p>The <code>event-valuechange</code> module adds a "valuechange" event that fires
when the <code>value</code> property of an <code><input></code> or <code><textarea></code> element changes as
the result of a keystroke, mouse operation, or input method editor (IME)
input event.</p>
</div>
<h2 id="whats-the-problem">What's the problem?</h2>
<p>The input related events provided by browsers don't cleanly address the
variety of ways users can modify an <code><input></code> or <code><textarea></code>'s
<code>value</code>. For example, users might change an input value by:</p>
<ul>
<li>typing a simple character</li>
<li>typing a multi-stroke character</li>
<li>
using an <a href="http://en.wikipedia.org/wiki/Input_method">Input
Method Editor</a>
</li>
<li>cutting from or pasting into the value with <code>Ctrl+X</code> or <code>Cmd+V</code></li>
<li>cutting or pasting with a keyboard-summoned context menu</li>
<li>cutting or pasting from the right-click context menu.</li>
</ul>
<p>The ideal change event would fire when the value becomes <em>something it
wasn't a moment ago</em>.</p>
<p>The <code>valuechange</code> event provides more reliable input notifications than
native events like <code>oninput</code> and <code>textInput</code>, particularly with changes that
result from multiple-keystroke IME input.</p>
<pre class="code prettyprint">commentTextarea.on('valuechange', updateLivePreview);</pre>
<h2 id="how-it-works">How it works</h2>
<p><code>valuechange</code> subscriptions monitor the element's value using a variety of
mechanisms including subscriptions to <code>focus</code> and various keyboard events, and a
poll to catch the stragglers. It seems like a lot of work, but it's the only
way to be sure.</p>
<p>Polling is only active when the element is focused, and only one element is
polled at a time, so the performance of your app should not be impacted.</p>
<h2 id="caveats">Caveats</h2>
<ul>
<li>
<p>
<code>valuechange</code> only supports subscriptions on <code><input></code> and
<code><textarea></code> elements, although it doesn't prevent you from subscribing
on other types of elements. If you subscribe on a different type of element
and stuff breaks, you were warned.
</p>
</li>
<li>
<p>
<code>valuechange</code> does not capture <code>value</code> updates done in JavaScript
<em>unless the input is currently focused and polling</em>. It's meant
to capture changes made by the user, not by other code. So:
<code>node.set('value', 'probably will not trigger valuechange');</code>
</p>
</li>
</ul>
</div>
</div>
</div>
<div class="yui3-u-1-4">
<div class="sidebar">
<div id="toc" class="sidebox">
<div class="hd">
<h2 class="no-toc">Table of Contents</h2>
</div>
<div class="bd">
<ul class="toc">
<li>
<a href="#whats-the-problem">What's the problem?</a>
</li>
<li>
<a href="#how-it-works">How it works</a>
</li>
<li>
<a href="#caveats">Caveats</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="Use the Event Utility to attach simple DOM event handlers.">
<a href="basic-example.html">Simple DOM Events</a>
</li>
<li data-description="Using the synthetic event API to create a DOM event that fires in response to arrow keys being pressed.">
<a href="synth-example.html">Creating an Arrow Event for DOM Subscription</a>
</li>
<li data-description="Supporting cross-device swipe gestures, using the event-move gesture events">
<a href="swipe-example.html">Supporting A Swipe Left Gesture</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples That Use This Component</h2>
</div>
<div class="bd">
<ul class="examples">
<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.">
<a href="../node-focusmanager/node-focusmanager-button.html">Accessible Menu Button</a>
</li>
<li data-description="Shows how to extend the base widget class, to create your own Widgets.">
<a href="../widget/widget-extend.html">Extending the Base Widget Class</a>
</li>
<li data-description="Example Photo Browser application.">
<a href="../dd/photo-browser.html">Photo Browser</a>
</li>
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation.">
<a href="../dd/portal-drag.html">Portal Style Example</a>
</li>
<li data-description="Use IO to request data over HTTP.">
<a href="../io/get.html">HTTP GET to request data</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script>
YUI.Env.Tests = {
examples: [],
project: '../assets',
assets: '../assets/event',
name: 'event',
title: 'The valuechange Event',
newWindow: '',
auto: false
};
YUI.Env.Tests.examples.push('basic-example');
YUI.Env.Tests.examples.push('synth-example');
YUI.Env.Tests.examples.push('swipe-example');
YUI.Env.Tests.examples.push('node-focusmanager-button');
YUI.Env.Tests.examples.push('widget-extend');
YUI.Env.Tests.examples.push('photo-browser');
YUI.Env.Tests.examples.push('portal-drag');
YUI.Env.Tests.examples.push('get');
</script>
<script src="../assets/yui/test-runner.js"></script>
</body>
</html>