diff --git a/public/js/ff/transactions/single/common.js b/public/js/ff/transactions/single/common.js index 90c63b7283..9f7b8da02f 100644 --- a/public/js/ff/transactions/single/common.js +++ b/public/js/ff/transactions/single/common.js @@ -164,7 +164,9 @@ function getTransferExchangeInstructions() { * When the transaction to create is a transfer some more checks are necessary. */ function validateCurrencyForTransfer() { + console.log('in validateCurrencyForTransfer()'); if (what !== "transfer") { + console.log('is not a transfer, so return.'); return; } $('#source_amount_holder').show(); diff --git a/public/js/ff/transactions/single/edit.js b/public/js/ff/transactions/single/edit.js index 47a9a4ea75..a7783893f7 100644 --- a/public/js/ff/transactions/single/edit.js +++ b/public/js/ff/transactions/single/edit.js @@ -37,16 +37,37 @@ $(document).ready(function () { }); $('#ffInput_amount').on('change', convertForeignToNative); - // respond to transfer changes: - $('#ffInput_source_id').on('change', function () { + // respond to account changes: + $('#ffInput_source_id').on('change', function (e) { + console.log('Event: #ffInput_source_id::change'); + + + validateCurrencyForTransfer(); // update the two source account currency ID fields (initial value): initCurrencyIdValues(); + + // call to selectsForeignCurrency + console.log('Extra call to selectsForeignCurrency()'); + selectsForeignCurrency(); + + // update "source_account_currency". + updateSourceAccountCurrency(); + }); $('#ffInput_destination_id').on('change', function () { + console.log('Event: #ffInput_destination_id::change'); validateCurrencyForTransfer(); // update the two source account currency ID fields (initial value): initCurrencyIdValues(); + + // call to selectsForeignCurrency + console.log('Extra call to selectsForeignCurrency()'); + selectsForeignCurrency(); + + // update "destination_account_currency". + updateDestinationAccountCurrency(); + }); // convert source currency to destination currency (slightly different routine for transfers) @@ -57,10 +78,37 @@ $(document).ready(function () { }); +/** + * Updates the currency ID of the hidden source account field + * to match the selected account. + */ +function updateSourceAccountCurrency() { + var accountId = $('#ffInput_source_id').val(); + var currency = parseInt(accountInfo[accountId].preferredCurrency); + console.log('Now in updateSourceAccountCurrency() for account #' + accountId); + console.log('Preferred currency for this account is #' + currency); + $('input[name="source_account_currency"]').val(currency); +} + +/** + * Updates the currency ID of the hidden destination account field + * to match the selected account. + */ +function updateDestinationAccountCurrency() { + var accountId = $('#ffInput_destination_id').val(); + var currency = parseInt(accountInfo[accountId].preferredCurrency); + console.log('Now in updateDestinationAccountCurrency() for account #' + accountId); + console.log('Preferred currency for this account is #' + currency); + $('input[name="destination_account_currency"]').val(currency); +} + + + /** * Fills two hidden variables with the correct currency ID. */ function initCurrencyIdValues() { + console.log('in initCurrencyIdValues()'); var currencyId; if (journal.transaction_type.type === "Withdrawal") { // update source from page load info: