3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
17 <div id="cls-Ext.ux.FieldReplicator"></div>/**
18 * @class Ext.ux.FieldReplicator
19 * <p>A plugin for Field Components which creates clones of the Field for as
20 * long as the user keeps filling them. Leaving the final one blank ends the repeating series.</p>
25 plugins: [ Ext.ux.FieldReplicator ],
27 fieldLabel: 'Select recipient',
32 Ext.ux.FieldReplicator = {
35 f.enableKeyEvents = true;
36 f.on('change', this.onChange, this);
37 f.onKeyDown = f.onKeyDown.createInterceptor(this.onKeyDown);
40 // If tabbing out and the change event will be fired, flag that
41 // the change handler must focus the correct sibling Field.
42 onKeyDown: function(e) {
43 if ((e.getKey() == Ext.EventObject.TAB) && (String(this.startValue) !== String(this.getValue()))) {
45 this.focusPrev = true;
46 } else if (!e.shiftKey && !e.altKey) {
47 this.focusNext = true;
52 // Handle the field either being changed to blank or from blank.
53 onChange: function(f, n, o) {
55 // Ensure that "change" is only fired once.
59 ps = f.previousSibling(),
62 if (!Ext.isEmpty(o)) {
63 // The Field has been blanked, and it is not the only one left, remove it
64 if ((ps && (ps.replicator === this)) || (ns && (ns.replicator === this))) {
65 l = f.findParentBy(function(p) {
66 return !Ext.isDefined(p.ownerCt);
74 // Field filled, insert a clone as the next sibling
75 ns = new f.constructor(f.cloneConfig());
76 c.insert(c.items.indexOf(f) + 1, ns);
78 l = f.findParentBy(function(p) {
79 return !Ext.isDefined(p.ownerCt);
86 ps.focus(false, true);
87 } else if (f.focusNext) {
89 ns.focus(false, true);