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.

CommentFileSizeAuthor
#1 currency_2471198_1.patch1.95 KBxano

Comments

xano’s picture

Version: 7.x-2.4 » 7.x-2.x-dev
Status: Active » Needs review
Issue tags: -DX (Developer Experience), -form API
StatusFileSize
new1.95 KB

Thanks 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?

Status: Needs review » Needs work

The last submitted patch, 1: currency_2471198_1.patch, failed testing.

ricovandevin’s picture

Status: Needs work » Reviewed & tested by the community

I can confirm that the patch works.

xano’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the review!

  • Xano committed 0424b34 on 7.x-2.x
    Issue #2471198 by Xano, ricovandevin: currency_amount form element does...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.