| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | ( function() { |
| 2 | - | |
| 3 | 2 | function addEventListeners() { |
| 4 | 3 | document.addEventListener( 'change', handleChangeEvent ); |
| 5 | 4 | document.addEventListener( 'keydown', handleKeyDownEvent ); |
| 6 | 5 | } |
| @@ -8,12 +7,16 @@ | ||
| 8 | 7 | function handleChangeEvent( e ) { |
| 9 | 8 | if ( 'INPUT' === e.target.nodeName && 'checkbox' === e.target.type && e.target.parentNode.classList.contains( 'frm_toggle_block' ) ) { |
| 10 | 9 | handleToggleChangeEvent( e ); |
| 11 | 10 | } |
| 11 | + | |
| 12 | + if ( 'frm_currency' === e.target.id ) { | |
| 13 | + syncCurrencyOptions( e.target ); | |
| 14 | + } | |
| 12 | 15 | } |
| 13 | 16 | |
| 14 | 17 | function handleKeyDownEvent( e ) { |
| 15 | - switch ( e.key ) { | |
| 18 | + switch ( e.key ) { // eslint-disable-line sonarjs/no-small-switch | |
| 16 | 19 | case ' ': |
| 17 | 20 | handleSpaceDownEvent( e ); |
| 18 | 21 | break; |
| 19 | 22 | } |
| @@ -20,8 +23,21 @@ | ||
| 20 | 23 | } |
| 21 | 24 | |
| 22 | 25 | function handleToggleChangeEvent( e ) { |
| 23 | 26 | e.target.nextElementSibling.setAttribute( 'aria-checked', e.target.checked ? 'true' : 'false' ); |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Updates the currency formatting options based on the selected currency. | |
| 31 | + * | |
| 32 | + * @param {HTMLSelectElement} currencySelect The currency select element. | |
| 33 | + */ | |
| 34 | + function syncCurrencyOptions( currencySelect ) { | |
| 35 | + const currency = frmSettings.currencies[ currencySelect.value ]; | |
| 36 | + | |
| 37 | + document.getElementById( 'frm_thousand_separator' ).value = currency.thousand_separator; | |
| 38 | + document.getElementById( 'frm_decimal_separator' ).value = currency.decimal_separator; | |
| 39 | + document.getElementById( 'frm_decimals' ).value = currency.decimals; | |
| 24 | 40 | } |
| 25 | 41 | |
| 26 | 42 | function handleSpaceDownEvent( e ) { |
| 27 | 43 | if ( e.target.classList.contains( 'frm_toggle' ) ) { |