Enforce the default selection of currency to stick even when no amount is entered.

I noticed that if the money field is not marked required and if there is no value entered, the form throws a warning on form save telling the user:

A valid amount is required when a currency is specified

Sometimes there is no value to be entered, yet we still want the default currency to be shown.

CommentFileSizeAuthor
#4 money.module.patch1.12 KBBodo Maass

Comments

markus_petrux’s picture

Ideally, it should be implemented as an option in the widget settings, where the default makes the widget work as it does now, so that we don't break the current functionality of the sites that are using this module.

I'm pretty busy, so I'm not sure to have the time to work on this. I would be open to review patches, though.

markus_petrux’s picture

Status: Active » Postponed

Postponing until I have the time, or someone else can come with a patch we can review.

Bodo Maass’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Status: Postponed » Needs review
StatusFileSize
new1.12 KB

Attached is a patch that addresses this problem.
Specifically:

1. The selected default currency is shown when existing nodes are edited. Previously, the default currency was shown only for new nodes, but not when editing existing nodes

2. The warning message that a valid amount is required when the currency is specified is not shown when a currency is selected but the value is empty.

markus_petrux’s picture

Status: Needs review » Needs work

I think this change could break existing sites, so there should be an option to enable the new behavior explicitly.

colan’s picture

Subscribe

davidwhthomas’s picture

Here's a node form form_alter snippet to set the default currency value

    // Set default currency select value for all money fields on the form
    $default_currency = variable_get('pt_default_currency', 'USD');
    foreach($form['#field_info'] as $field_name => $field){
      if($field['type'] == 'money'){
        $form[$field_name][0]['#default_value']['currency'] = $default_currency;        
      }
    }

It doesn't fix the issue when no value is entered for amount and the currency is set as default though.. but may help.

kenorb’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.