From 184a9a4c095cc9e4600135d7060525c793918a58 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Tue, 11 Jun 2019 17:15:21 -0400 Subject: [PATCH] submit tx on blur --- src/app/transaction/autocomplete.html | 2 +- src/app/transaction/autocomplete.ts | 7 +++++++ src/app/transaction/list.html | 24 ++++++++++++------------ src/app/transaction/list.ts | 25 +++++++++++++++++++++---- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/app/transaction/autocomplete.html b/src/app/transaction/autocomplete.html index 256c318..c51ab06 100644 --- a/src/app/transaction/autocomplete.html +++ b/src/app/transaction/autocomplete.html @@ -1,4 +1,4 @@ -
+
{{tx.description}} diff --git a/src/app/transaction/autocomplete.ts b/src/app/transaction/autocomplete.ts index f9842fd..167a39f 100644 --- a/src/app/transaction/autocomplete.ts +++ b/src/app/transaction/autocomplete.ts @@ -15,6 +15,7 @@ export class Autocomplete { @Input() item: TxItem; @Input() accountId: string; @Output() tx = new EventEmitter(); + @Output() interact = new EventEmitter(); public visible: boolean; public txs$: Observable; @@ -65,4 +66,10 @@ export class Autocomplete { this.visible = false; } + preventBlur() { + // used to notify parent that autocomplete has been interacted with and + // that it should not try to do any onBlur() stuff + this.interact.emit(true); + } + } \ No newline at end of file diff --git a/src/app/transaction/list.html b/src/app/transaction/list.html index 48ac783..2b74137 100644 --- a/src/app/transaction/list.html +++ b/src/app/transaction/list.html @@ -36,16 +36,16 @@
{{item.tx.date | date:"M/d/y"}} - +
{{item.tx.description}}
- - + +
{{getTransferString(item) | slice:0:50}} - @@ -53,11 +53,11 @@
{{getDebit(item) | currencyFormat:account.precision:account.currency}} - +
{{getCredit(item) | currencyFormat:account.precision:account.currency}} - +
{{item.balance | currencyFormat:account.precision:account.currency}} @@ -82,20 +82,20 @@ Remove Split
-
-
- +
+
-
- +
+
diff --git a/src/app/transaction/list.ts b/src/app/transaction/list.ts index 0a53177..6135d99 100644 --- a/src/app/transaction/list.ts +++ b/src/app/transaction/list.ts @@ -452,8 +452,14 @@ export class TxListPage implements OnInit, AfterViewChecked { item.preventBlur = true; } - onBlur(item: TxItem) { + onBlur(item: TxItem, $event) { this.log.debug('blur2'); + let elem = document.activeElement as any; + + if(elem.form && elem.form.id === 'form' + item.tx.id + item.activeSplitIndex) { + // no blur if newly clicked element is in the same form + return; + } setTimeout(() => { this.log.debug('blur', item.form.pristine); @@ -462,12 +468,16 @@ export class TxListPage implements OnInit, AfterViewChecked { return; } - if(!item.form.pristine) { + let elem = document.activeElement as any; + if(elem.form && elem.form.id === 'form' + item.tx.id + item.activeSplitIndex) { + // no blur if newly clicked element is in the same form return; } - let elem = document.activeElement as any; - if(elem.form && elem.form.id === 'form' + item.tx.id + item.activeSplitIndex) { + if(!item.form.pristine) { + // if there are changes, submit the form + $event.target.blur(); + this.submit(item); return; } @@ -523,6 +533,12 @@ export class TxListPage implements OnInit, AfterViewChecked { splits.push(control); this.fillEmptySplit(item); + // TODO how to focus newly created split in non-hacky way? + setTimeout(() => { + let rows: HTMLElement[] = Array.from(document.querySelectorAll('#form' + item.tx.id + item.activeSplitIndex + ' .row')); + let input: any = rows[rows.length - 1].querySelectorAll('.debit input')[0]; + input && input.focus(); + }, 10); } addFirstSplit(item: TxItem) { @@ -765,6 +781,7 @@ export class TxListPage implements OnInit, AfterViewChecked { } onEnter(item, $event) { + item.preventBlur = true; $event.target.blur(); this.submit(item); }