Skip to content

Commit

Permalink
BUGFIX Passing $name in MoneyField->FieldCurrency() (fixes #5982, tha…
Browse files Browse the repository at this point in the history
…nks andersw) (from r110835)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112848 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
Sam Minnee committed Oct 19, 2010
1 parent 61bb2fe commit 9d4d730
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions forms/MoneyField.php
Expand Up @@ -31,7 +31,7 @@ class MoneyField extends FormField {
function __construct($name, $title = null, $value = "", $form = null) { function __construct($name, $title = null, $value = "", $form = null) {
// naming with underscores to prevent values from actually being saved somewhere // naming with underscores to prevent values from actually being saved somewhere
$this->fieldAmount = new NumericField("{$name}[Amount]", _t('MoneyField.FIELDLABELAMOUNT', 'Amount')); $this->fieldAmount = new NumericField("{$name}[Amount]", _t('MoneyField.FIELDLABELAMOUNT', 'Amount'));
$this->fieldCurrency = $this->FieldCurrency(); $this->fieldCurrency = $this->FieldCurrency($name);


parent::__construct($name, $title, $value, $form); parent::__construct($name, $title, $value, $form);
} }
Expand All @@ -47,19 +47,20 @@ function Field() {
} }


/** /**
* @param string $name - Name of field
* @return FormField * @return FormField
*/ */
protected function FieldCurrency() { protected function FieldCurrency($name) {
$allowedCurrencies = $this->getAllowedCurrencies(); $allowedCurrencies = $this->getAllowedCurrencies();
if($allowedCurrencies) { if($allowedCurrencies) {
$field = new DropdownField( $field = new DropdownField(
"{$this->name}[Currency]", "{$name}[Currency]",
_t('MoneyField.FIELDLABELCURRENCY', 'Currency'), _t('MoneyField.FIELDLABELCURRENCY', 'Currency'),
ArrayLib::is_associative($allowedCurrencies) ? $allowedCurrencies : array_combine($allowedCurrencies,$allowedCurrencies) ArrayLib::is_associative($allowedCurrencies) ? $allowedCurrencies : array_combine($allowedCurrencies,$allowedCurrencies)
); );
} else { } else {
$field = new TextField( $field = new TextField(
"{$this->name}[Currency]", "{$name}[Currency]",
_t('MoneyField.FIELDLABELCURRENCY', 'Currency') _t('MoneyField.FIELDLABELCURRENCY', 'Currency')
); );
} }
Expand Down Expand Up @@ -136,7 +137,7 @@ function setAllowedCurrencies($arr) {


// @todo Has to be done twice in case allowed currencies changed since construction // @todo Has to be done twice in case allowed currencies changed since construction
$oldVal = $this->fieldCurrency->Value(); $oldVal = $this->fieldCurrency->Value();
$this->fieldCurrency = $this->FieldCurrency(); $this->fieldCurrency = $this->FieldCurrency($this->name);
$this->fieldCurrency->setValue($oldVal); $this->fieldCurrency->setValue($oldVal);
} }


Expand Down

0 comments on commit 9d4d730

Please sign in to comment.