3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
10 * @class Ext.ux.FieldReplicator
\r
11 * <p>A plugin for Field Components which creates clones of the Field for as
\r
12 * long as the user keeps filling them. Leaving the final one blank ends the repeating series.</p>
\r
17 plugins: [ Ext.ux.FieldReplicator ],
\r
18 triggerAction: 'all',
\r
19 fieldLabel: 'Select recipient',
\r
20 store: recipientStore
\r
24 Ext.ux.FieldReplicator = {
\r
26 f.replicator = this;
\r
27 f.enableKeyEvents = true;
\r
28 f.on('change', this.onChange, this);
\r
29 f.onKeyDown = f.onKeyDown.createInterceptor(this.onKeyDown);
\r
32 // If tabbing out and the change event will be fired, flag that
\r
33 // the change handler must focus the correct sibling Field.
\r
34 onKeyDown: function(e) {
\r
35 if ((e.getKey() == Ext.EventObject.TAB) && (String(this.startValue) !== String(this.getValue()))) {
\r
37 this.focusPrev = true;
\r
38 } else if (!e.shiftKey && !e.altKey) {
\r
39 this.focusNext = true;
\r
44 // Handle the field either being changed to blank or from blank.
\r
45 onChange: function(f, n, o) {
\r
47 // Ensure that "change" is only fired once.
\r
50 var c = f.ownerCt, l,
\r
51 ps = f.previousSibling(),
\r
52 ns = f.nextSibling();
\r
53 if (Ext.isEmpty(n)) {
\r
54 if (!Ext.isEmpty(o)) {
\r
55 // The Field has been blanked, and it is not the only one left, remove it
\r
56 if ((ps && (ps.replicator === this)) || (ns && (ns.replicator === this))) {
\r
57 l = f.findParentBy(function(p) {
\r
58 return !Ext.isDefined(p.ownerCt);
\r
65 if (Ext.isEmpty(o)) {
\r
66 // Field filled, insert a clone as the next sibling
\r
67 ns = new f.constructor(f.cloneConfig());
\r
68 c.insert(c.items.indexOf(f) + 1, ns);
\r
70 l = f.findParentBy(function(p) {
\r
71 return !Ext.isDefined(p.ownerCt);
\r
78 ps.focus(false, true);
\r
79 } else if (f.focusNext) {
\r
81 ns.focus(false, true);
\r