I use Currency's form element to drive some custom entity forms. Forms configured with a Currency form element are supposed to accept a #default_value with a Currency value (associative array with "amount" and "currency_code" values). However, creating a form element with a properly configured #default_value and #currency_code set FALSE results in the form always displaying with "No currency (XXX)" listed despite whatever was put into #default_value.
Upon further examination it appears that the default value currency code is overridden in currency_form_currency_amount_process on line 257, which re-declares an option from line 251. I'm assuming the second declaration was to provide a fallback (i.e. if the currency code isn't set, ensure it's set to XXX). In that case, you would need to remove line 257 and change line 251 to read
'#default_value' => isset($element['#default_value']['currency_code']) ? $element['#default_value']['currency_code'] : "XXX",
This will allow developers using Currency's form elements directly to provide user-selectable currency codes.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | currency_2471198_1.patch | 1.95 KB | xano |
Comments
Comment #1
xanoThanks for reporting this bug! The attached patch improves form element validation and should load the correct currency. Could you test if it works for you?
Comment #3
ricovandevin commentedI can confirm that the patch works.
Comment #4
xanoThanks for the review!