Skip to content

Commit 54a4578

Browse files
committed
improve form handling
1 parent 527869d commit 54a4578

File tree

6 files changed

+18
-8
lines changed

6 files changed

+18
-8
lines changed

projects/fusio-sdk/src/lib/component/form/autocomplete/form-autocomplete.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
[editable]="false"
1313
(ngModelChange)="changeValue()"
1414
[disabled]="disabled"
15+
(keydown.enter)="enter.emit()"
16+
placeholder="Type to search ..."
1517
class="form-control"
1618
/>
1719
<button class="btn btn-outline-secondary" type="button" disabled *ngIf="searching">

projects/fusio-sdk/src/lib/component/form/autocomplete/form-autocomplete.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
1+
import {Component, EventEmitter, Input, OnChanges, OnInit, Output} from '@angular/core';
22
import {IdAndName, Service} from "../../../abstract/service";
33
import {catchError, debounceTime, distinctUntilChanged, map, merge, Observable, of, OperatorFunction, Subject, switchMap, tap} from "rxjs";
44
import {fromPromise} from "rxjs/internal/observable/innerFrom";
@@ -16,6 +16,7 @@ export class FormAutocompleteComponent implements OnInit {
1616
@Input() service!: Service<any>;
1717
@Input() useName: boolean = false;
1818
@Output() dataChange = new EventEmitter<string>();
19+
@Output() enter = new EventEmitter<void>();
1920

2021
focus$ = new Subject<string>();
2122

projects/fusio-sdk/src/lib/component/form/list/form-list.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</div>
99
</ng-container>
1010
<ng-container *ngIf="type === 'autocomplete' && service">
11-
<fusio-form-autocomplete id="{{name}}-{{i}}" name="{{name}}-{{i}}" [service]="service" [data]="property.value" (dataChange)="doChange(i, $event)" [disabled]="disabled">
11+
<fusio-form-autocomplete id="{{name}}-{{i}}" name="{{name}}-{{i}}" [service]="service" [useName]="useName" [data]="property.value" (dataChange)="doChange(i, $event)" [disabled]="disabled">
1212
<button class="btn btn-danger" type="button" (click)="doRemove(i)"><i class="bi bi-x"></i></button>
1313
</fusio-form-autocomplete>
1414
</ng-container>
@@ -18,12 +18,12 @@
1818
<div class="col-sm-12">
1919
<ng-container *ngIf="type !== 'autocomplete'">
2020
<div class="input-group">
21-
<input id="{{name}}-newValue" name="{{name}}-newValue" type="{{type}}" [(ngModel)]="newValue" class="form-control">
21+
<input id="{{name}}-newValue" name="{{name}}-newValue" type="{{type}}" [(ngModel)]="newValue" (keydown.enter)="doAdd()" placeholder="Enter value" class="form-control">
2222
<button class="btn btn-success" type="button" (click)="doAdd()"><i class="bi bi-plus"></i></button>
2323
</div>
2424
</ng-container>
2525
<ng-container *ngIf="type === 'autocomplete' && service">
26-
<fusio-form-autocomplete id="{{name}}-newValue" name="{{name}}-newValue" [service]="service" [data]="newValue" (dataChange)="newValue = $event" [disabled]="disabled">
26+
<fusio-form-autocomplete id="{{name}}-newValue" name="{{name}}-newValue" [service]="service" [useName]="useName" [data]="newValue" (dataChange)="newValue = $event; doAdd()" (enter)="doAdd()" [disabled]="disabled">
2727
<button class="btn btn-success" type="button" (click)="doAdd()"><i class="bi bi-plus"></i></button>
2828
</fusio-form-autocomplete>
2929
</ng-container>

projects/fusio-sdk/src/lib/component/form/list/form-list.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class FormListComponent implements OnInit {
1313
@Input() type: string = 'text';
1414
@Input() data: Array<string> = [];
1515
@Input() service?: Service<any>;
16+
@Input() useName: boolean = false;
1617
@Output() dataChange = new EventEmitter<Array<string>>();
1718

1819
local: Array<any> = [];

projects/fusio-sdk/src/lib/component/form/map/form-map.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
</div>
99
</ng-container>
1010
<ng-container *ngIf="type === 'autocomplete' && service">
11-
<fusio-form-autocomplete id="{{name}}-{{property.key}}" name="{{name}}-{{property.key}}" [service]="service" [data]="property.value" (dataChange)="doChange(i, $event)">
11+
<fusio-form-autocomplete id="{{name}}-{{property.key}}" name="{{name}}-{{property.key}}" [service]="service" [useName]="useName" [data]="property.value" (dataChange)="doChange(i, $event)">
1212
<button class="btn btn-danger" type="button" (click)="doRemove(i)"><i class="bi bi-x"></i></button>
1313
</fusio-form-autocomplete>
1414
</ng-container>
1515
</div>
1616
</div>
1717
<div class="mb-3 row">
1818
<div class="col-sm-2">
19-
<input type="text" id="{{name}}-newKey" name="{{name}}-newKey" [(ngModel)]="newKey" class="form-control">
19+
<input type="text" id="{{name}}-newKey" name="{{name}}-newKey" [(ngModel)]="newKey" placeholder="Enter key" class="form-control">
2020
</div>
2121
<div class="col-sm-10">
2222
<ng-container *ngIf="type !== 'autocomplete'">
2323
<div class="input-group">
24-
<input type="{{type}}" id="{{name}}-newValue" name="{{name}}-newValue" [(ngModel)]="newValue" class="form-control">
24+
<input type="{{type}}" id="{{name}}-newValue" name="{{name}}-newValue" [(ngModel)]="newValue" (keydown.enter)="doAdd()" placeholder="Enter value" class="form-control">
2525
<button class="btn btn-success" type="button" (click)="doAdd()"><i class="bi bi-plus"></i></button>
2626
</div>
2727
</ng-container>
2828
<ng-container *ngIf="type === 'autocomplete' && service">
29-
<fusio-form-autocomplete id="{{name}}-newValue" name="{{name}}-newValue" [service]="service" [data]="newValue" (dataChange)="newValue = $event">
29+
<fusio-form-autocomplete id="{{name}}-newValue" name="{{name}}-newValue" [service]="service" [useName]="useName" [data]="newValue" (dataChange)="newValue = $event" (enter)="doAdd()" [disabled]="disabled">
3030
<button class="btn btn-success" type="button" (click)="doAdd()"><i class="bi bi-plus"></i></button>
3131
</fusio-form-autocomplete>
3232
</ng-container>

projects/fusio-sdk/src/lib/component/form/map/form-map.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class FormMapComponent implements OnInit {
1313
@Input() type: string = 'text';
1414
@Input() data: Record<string, string> = {};
1515
@Input() service?: Service<any>;
16+
@Input() useName: boolean = false;
1617
@Output() dataChange = new EventEmitter<Record<string, string>>();
1718

1819
local: Array<Entry> = [];
@@ -50,6 +51,11 @@ export class FormMapComponent implements OnInit {
5051
this.newKey = '';
5152
this.newValue = '';
5253
this.dataChange.emit(this.fromLocal());
54+
55+
const elKey = document.getElementById(this.name + '-newKey');
56+
if (elKey instanceof HTMLInputElement) {
57+
elKey.focus();
58+
}
5359
}
5460

5561
doRemove(index: number) {

0 commit comments

Comments
 (0)