Hello thanks for the module, i've just set a cck money field. I selected eur and usd as my field currencies but i would set a default value too.

when i set a value (in php format too), system tells me those errors:

The currency EUR is not allowed. (but it it enabled!)
Default value is invalid.

Has anyone the same issue?

Then the Eur decimal and group separator are inverted.

Thanks for help.
jM

Comments

johnmullin2003’s picture

edit: about decimal separator, I solved this issue in Currency section.. sorry I didn't see it before.

about the default currency and default value, issue is still active...

thanks all for suggestions/help.

markus_petrux’s picture

Category: support » bug
Status: Active » Needs review

Oh, I see. It seems that CCK is not passing the allowed currencies option where we expect.

Please, edit the money.module and replace function money_validate_field_value() with this one:

function money_validate_field_value($field, $amount, $currency) {
  $widget_label = t($field['widget']['label']);
  $errors = array();
  if (empty($currency)) {
    if ($field['required']) {
      $errors[] = t('%name: Currency is required.', array('%name' => $widget_label));
    }
    else if (is_numeric($amount)) {
      $errors[] = t('%name: Currency is required when an amount is specified.', array('%name' => $widget_label));
    }
  }
  else {
    // When validating the default value in field settings panel, CCK is giving
    // us the options at field level, not within the widget item of the field.
    if (!empty($field['allowed_currencies'])) {
      $allowed_currencies = (isset($field['allowed_currencies']) ? array_filter($field['allowed_currencies']) : array());
      $amount_required = FALSE;
    }
    else {
      $allowed_currencies = (isset($field['widget']['allowed_currencies']) ? array_filter($field['widget']['allowed_currencies']) : array());
      $amount_required = TRUE;
    }
    // When no currency is enabled, allow them all.
    if (empty($allowed_currencies)) {
      $allowed_currencies = currency_api_get_list();
    }
    if (!isset($allowed_currencies[$currency])) {
      if (!$field['required']) {
        $errors[] = t('%name: The currency %currency is not allowed.', array('%name' => $widget_label, '%currency' => $currency));
      }
    }
    else if (!is_numeric($amount) && $amount_required) {
      $errors[] = t('%name: A valid amount is required when a currency is specified.', array('%name' => $widget_label));
    }
  }
  return $errors;
}

Works?

markus_petrux’s picture

Title: Set the default value and decimal separator » Currency not allowed when setting the default value of the field
Jonah Fenn’s picture

markus -

I'm running into the same issue. I'm using Drupal 6.9. The currency module is a new install for me so I don't have any point of reference prior to 6.9.

After patching the money.module, it didn't throw an error message after setting the default value (US Dollars) but when I went to test the content, it just gave me a -- as my selection option.

I blew out the field and attempted to rebuild it and then, oddly enough, received the original error message again.

Thanks, in advance, for any additional help you might provide with this.

haggins’s picture

This patch works for me (Drupal 6.9), thx Markus!

markus_petrux’s picture

Status: Needs review » Fixed

Fixed in CVS. Thanks

markus_petrux’s picture

Status: Fixed » Closed (fixed)