Skip to content

Conversation

@abiteman
Copy link
Contributor

Fixes #32

Issue

Fixed issue #32 where editing a transaction would throw a ReferenceError: currentTransactionType is not defined error. This occurred when trying to edit a transaction after previously editing another transaction.

Changes Made

  • Moved all global variable declarations to the top of the file for better organization and initialization
  • Consolidated scattered variable declarations into a single global variables section
  • Ensured currentTransactionType is properly initialized before any function usage
  • Removed duplicate declarations that were scattered throughout the file

Technical Details

The issue was caused by the currentTransactionType variable being declared in the middle of the file, which could lead to reference errors if the code execution path didn't reach that declaration before using the variable. By moving it to the top of the file with other global variables, we ensure it's always properly initialized before use.

Testing

The fix has been tested by:

  1. Editing an expense transaction
  2. Editing an income transaction
  3. Verifying that the transaction type remains correct during edits
  4. Confirming no more reference errors occur

Impact

This change improves the reliability of the transaction editing functionality and prevents potential type switching issues when editing different types of transactions in sequence.

abiteman added 3 commits May 17, 2025 21:14
The bug was caused by a missing update to the currentTransactionType variable in the editTransaction function. Here's what was happening:
When you edit a transaction, the UI correctly shows the transaction type (income or expense) by toggling the appropriate button visually.
However, the currentTransactionType variable (which is used when saving the form) wasn't being updated.
This variable was only updated when a user manually clicked the type toggle buttons.
When submitting the form, it used whatever value was in currentTransactionType instead of the actual type of the edited transaction.
So the sequence of events in the bug was:
Edit an expense transaction (the UI shows "expense" is selected, but currentTransactionType gets set to "expense")
Submit the update (it works correctly)
Edit an income transaction (the UI shows "income" is selected, but currentTransactionType still has "expense" from the previous edit)
Submit the update (it incorrectly uses "expense" as the type, converting the income to an expense)
script.js:474 Uncaught ReferenceError: currentTransactionType is not defined
    at editTransaction (script.js:474:28)
    at HTMLDivElement.<anonymous> (script.js:404:17)
@abiteman abiteman merged commit 2a2f36b into main May 18, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug, Post might changes type on update

2 participants