]>
git.proxmox.com Git - extjs.git/blob - extjs/packages/ux/classic/src/FieldReplicator.js
2 * <p>A plugin for Field Components which creates clones of the Field for as
3 * long as the user keeps filling them. Leaving the final one blank ends the repeating series.</p>
8 plugins: [ Ext.ux.FieldReplicator ],
10 fieldLabel: 'Select recipient',
15 Ext
.define('Ext.ux.FieldReplicator', {
16 alias
: 'plugin.fieldreplicator',
18 init: function(field
) {
19 // Assign the field an id grouping it with fields cloned from it. If it already
20 // has an id that means it is itself a clone.
21 if (!field
.replicatorId
) {
22 field
.replicatorId
= Ext
.id();
25 field
.on('blur', this.onBlur
, this);
28 onBlur: function(field
) {
29 var ownerCt
= field
.ownerCt
,
30 replicatorId
= field
.replicatorId
,
31 isEmpty
= Ext
.isEmpty(field
.getRawValue()),
32 siblings
= ownerCt
.query('[replicatorId=' + replicatorId
+ ']'),
33 isLastInGroup
= siblings
[siblings
.length
- 1] === field
,
36 // If a field before the final one was blanked out, remove it
37 if (isEmpty
&& !isLastInGroup
) {
38 Ext
.Function
.defer(field
.destroy
, 10, field
); //delay to allow tab key to move focus first
40 // If the field is the last in the list and has a value, add a cloned field after it
41 else if(!isEmpty
&& isLastInGroup
) {
42 if (field
.onReplicate
) {
45 clone
= field
.cloneConfig({replicatorId
: replicatorId
});
46 idx
= ownerCt
.items
.indexOf(field
);
47 ownerCt
.add(idx
+ 1, clone
);