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