mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-22 14:49:38 +02:00
Shared money input should respond to change in currency (#654)
* Add step method to currency * Change amount placeholder and step, when currency select change * Lint * Add test with auth * Extract request to specific service
This commit is contained in:
parent
c46662c99f
commit
5be1ced19e
10 changed files with 63 additions and 6 deletions
20
app/javascript/controllers/money_field_controller.js
Normal file
20
app/javascript/controllers/money_field_controller.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import { Controller } from "@hotwired/stimulus";
|
||||
import { CurrenciesService } from "services/currencies_service";
|
||||
|
||||
// Connects to data-controller="money-field"
|
||||
// when currency select change, update the input value with the correct placeholder and step
|
||||
export default class extends Controller {
|
||||
static targets = ["amount", "currency"];
|
||||
|
||||
handleCurrencyChange() {
|
||||
const selectedCurrency = event.target.value;
|
||||
this.updateAmount(selectedCurrency);
|
||||
}
|
||||
|
||||
updateAmount(currency) {
|
||||
(new CurrenciesService).get(currency).then((data) => {
|
||||
this.amountTarget.placeholder = data.placeholder;
|
||||
this.amountTarget.step = data.step;
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue