Skip to content

Commit 0e1ed89

Browse files
committed
Disableable drag-n-drop
1 parent 574707e commit 0e1ed89

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The following parameters can be set on a dual-list:
4242
- **display** - The field of each object for displaying the object each the
4343
lists, default is ``_name``. (With a source of an array of strings, each string is its own display.)
4444
- **height** - The height of the lists, default is ``100px``.
45-
- **format** - A format object, default is ``{ add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: 'left-to-right' }``
45+
- **format** - A format object, default is ``{ add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: 'left-to-right', draggable: true }``
4646
- **filter** - A boolean whether or not to display a filter for the lists, default is ``false``.
4747
- **sort** - A boolean whether or not to keep the lists sorted, default is ``false``.
4848
- **compare** - A compare function to be used for sorting the lists. Note if

app/demo-app.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DualListComponent } from 'angular-dual-listbox';
55

66
@Component({
77
selector: 'demo-app',
8+
styles: [ '.form-group { margin-bottom: 16px; }', '.checkbox { margin-top: inherit }' ],
89
template: `
910
<div class="container-fluid">
1011
<p></p>
@@ -52,6 +53,12 @@ import { DualListComponent } from 'angular-dual-listbox';
5253
<label>None button</label>
5354
<input class="form-control col-sm-2" [(ngModel)]="format.none" name="noneBtn">
5455
</div>
56+
<div class="form-group">
57+
<label>Enable drag-and-drop</label>
58+
<div class="checkbox">
59+
<label><input type="checkbox" [(ngModel)]="format.draggable" name="drag">draggable</label>
60+
</div>
61+
</div>
5562
</form>
5663
</div>
5764

lib/dual-list.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<li *ngFor="let item of available.sift; let idx=index;"
1515
(click)="disabled ? null : selectItem(available.pick, item); shiftClick($event, idx, available, item)"
1616
[ngClass]="{selected: isItemSelected(available.pick, item), disabled: disabled}"
17-
[draggable]="!disabled" (dragstart)="drag($event, item, available)" (dragend)="dragEnd(available)"
17+
[draggable]="!disabled && format.draggable" (dragstart)="drag($event, item, available)" (dragend)="dragEnd(available)"
1818
><label>{{item._name}}</label></li>
1919
</ul>
2020
</div>
@@ -42,7 +42,7 @@
4242
<li #itmConf *ngFor="let item of confirmed.sift; let idx=index;"
4343
(click)="disabled ? null : selectItem(confirmed.pick, item); shiftClick($event, idx, confirmed, item)"
4444
[ngClass]="{selected: isItemSelected(confirmed.pick, item), disabled: disabled}"
45-
[draggable]="!disabled" (dragstart)="drag($event, item, confirmed)" (dragend)="dragEnd(confirmed)"
45+
[draggable]="!disabled && format.draggable" (dragstart)="drag($event, item, confirmed)" (dragend)="dragEnd(confirmed)"
4646
><label>{{item._name}}</label></li>
4747
</ul>
4848
</div>

lib/dual-list.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class DualListComponent implements DoCheck, OnChanges {
2020
static LTR = 'left-to-right';
2121
static RTL = 'right-to-left';
2222

23-
static DEFAULT_FORMAT = { add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: DualListComponent.LTR };
23+
static DEFAULT_FORMAT = { add: 'Add', remove: 'Remove', all: 'All', none: 'None', direction: DualListComponent.LTR, draggable: true };
2424

2525
@Input() id = `dual-list-${nextId++}`;
2626
@Input() key = '_id';
@@ -86,6 +86,10 @@ export class DualListComponent implements DoCheck, OnChanges {
8686
if (typeof(this.format.none) === 'undefined') {
8787
this.format.none = DualListComponent.DEFAULT_FORMAT.none;
8888
}
89+
90+
if (typeof(this.format.draggable) === 'undefined') {
91+
this.format.draggable = DualListComponent.DEFAULT_FORMAT.draggable;
92+
}
8993
}
9094

9195
if (changeRecord['source']) {

0 commit comments

Comments
 (0)