3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js">Ext.ns("Ext.ux");
\r
10 <div id="cls-Ext.ux.FieldReplicator"></div>/**
\r
11 * @class Ext.ux.FieldReplicator
\r
12 * <p>A plugin for Field Components which creates clones of the Field for as
\r
13 * long as the user keeps filling them. Leaving the final one blank ends the repeating series.</p>
\r
18 plugins: [ Ext.ux.FieldReplicator ],
\r
19 triggerAction: 'all',
\r
20 fieldLabel: 'Select recipient',
\r
21 store: recipientStore
\r
25 Ext.ux.FieldReplicator = {
\r
27 f.replicator = this;
\r
28 f.enableKeyEvents = true;
\r
29 f.on('change', this.onChange, this);
\r
30 f.onKeyDown = f.onKeyDown.createInterceptor(this.onKeyDown);
\r
33 // If tabbing out and the change event will be fired, flag that
\r
34 // the change handler must focus the correct sibling Field.
\r
35 onKeyDown: function(e) {
\r
36 if ((e.getKey() == Ext.EventObject.TAB) && (String(this.startValue) !== String(this.getValue()))) {
\r
38 this.focusPrev = true;
\r
39 } else if (!e.shiftKey && !e.altKey) {
\r
40 this.focusNext = true;
\r
45 // Handle the field either being changed to blank or from blank.
\r
46 onChange: function(f, n, o) {
\r
47 var c = f.ownerCt, l,
\r
48 ps = f.previousSibling(),
\r
49 ns = f.nextSibling();
\r
50 if (Ext.isEmpty(n)) {
\r
51 if (!Ext.isEmpty(o)) {
\r
52 // The Field has been blanked, and it is not the only one left, remove it
\r
53 if ((ps && (ps.replicator === this)) || (ns && (ns.replicator === this))) {
\r
54 l = f.findParentBy(function(p) {
\r
55 return !Ext.isDefined(p.ownerCt);
\r
62 if (Ext.isEmpty(o)) {
\r
63 // Field filled, insert a clone as the next sibling
\r
64 ns = new f.constructor(f.cloneConfig());
\r
65 c.insert(c.items.indexOf(f) + 1, ns);
\r
67 l = f.findParentBy(function(p) {
\r
68 return !Ext.isDefined(p.ownerCt);
\r
75 ps.focus(false, true);
\r
76 } else if (f.focusNext) {
\r
78 ns.focus(false, true);
\r