mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 15:19:38 +02:00
Update properties controller to use new creational and update balance methods
This commit is contained in:
parent
d459ebdad8
commit
25f0c78c47
17 changed files with 500 additions and 144 deletions
|
@ -5,10 +5,15 @@ import { CurrenciesService } from "services/currencies_service";
|
|||
// when currency select change, update the input value with the correct placeholder and step
|
||||
export default class extends Controller {
|
||||
static targets = ["amount", "currency", "symbol"];
|
||||
static values = { syncCurrency: Boolean };
|
||||
|
||||
handleCurrencyChange(e) {
|
||||
const selectedCurrency = e.target.value;
|
||||
this.updateAmount(selectedCurrency);
|
||||
|
||||
if (this.syncCurrencyValue) {
|
||||
this.syncOtherMoneyFields(selectedCurrency);
|
||||
}
|
||||
}
|
||||
|
||||
updateAmount(currency) {
|
||||
|
@ -24,4 +29,28 @@ export default class extends Controller {
|
|||
this.symbolTarget.innerText = currency.symbol;
|
||||
});
|
||||
}
|
||||
|
||||
syncOtherMoneyFields(selectedCurrency) {
|
||||
// Find the form this money field belongs to
|
||||
const form = this.element.closest("form");
|
||||
if (!form) return;
|
||||
|
||||
// Find all other money field controllers in the same form
|
||||
const allMoneyFields = form.querySelectorAll('[data-controller~="money-field"]');
|
||||
|
||||
allMoneyFields.forEach(field => {
|
||||
// Skip the current field
|
||||
if (field === this.element) return;
|
||||
|
||||
// Get the controller instance
|
||||
const controller = this.application.getControllerForElementAndIdentifier(field, "money-field");
|
||||
if (!controller) return;
|
||||
|
||||
// Update the currency select if it exists
|
||||
if (controller.hasCurrencyTarget) {
|
||||
controller.currencyTarget.value = selectedCurrency;
|
||||
controller.updateAmount(selectedCurrency);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue