<div class="modal-body">
<p>{{dialogBody}}</p>
<div class="text-center">
- <input type="{{promptType}}" class="form-control"
+ <input type="{{promptType}}" class="form-control" id="{{inputDomId}}"
[attr.min]="promptType == 'number' ? promptMin : ''"
[attr.max]="promptType == 'number' ? promptMax : ''"
- [(ngModel)]="promptValue"/>
+ (keyup.enter)="close(promptValue)" [(ngModel)]="promptValue"/>
</div>
</div>
<div class="modal-footer">
-import {Component, Input, ViewChild, TemplateRef} from '@angular/core';
+import {Component, Input, ViewChild, OnInit, TemplateRef} from '@angular/core';
import {DialogComponent} from '@eg/share/dialog/dialog.component';
@Component({
/**
* Promptation dialog that requests user input.
*/
-export class PromptDialogComponent extends DialogComponent {
+export class PromptDialogComponent extends DialogComponent implements OnInit {
+ static domId = 0;
+
+ @Input() inputDomId = 'eg-prompt-dialog-' + PromptDialogComponent.domId++;
+
// What question are we asking?
@Input() public dialogBody: string;
// Value to return to the caller
// May be used when promptType == 'number'
@Input() promptMin: number = null;
@Input() promptMax: number = null;
+
+ ngOnInit() {
+ this.onOpen$.subscribe(_ => {
+ const node = document.getElementById(this.inputDomId);
+ if (node) { node.focus(); node.select(); }
+ });
+ }
}