Remember me? forgot password | register

SilverStripe Forum

10664 Posts in 2786 Topics by 1517 members

Jump to:

Site Builders

If this is your first visit, you will need to register before you can post. However, you can browse all messages below.

Community » SilverStripe Forum » Site Builders » CurrencyField Format
Page: 1 go to end Reply
Author Topic: CurrencyField Format 903 views
  • Aaron
    Aaron's avatar
    Community Member
    63 posts

    CurrencyField Format Link to this post

    Hi there,
    I'm doing a custom sales solution and we are selling products that are available in 4 Currencies, US, UK, AUS and NZ
    I have added four CurrencyFields to the cms, however I notice that after saving, the default behavior is to put '$' symbols in the field.
    Am I able to change the currency format on a per-field basis?
    Also, what's the deal with validation? I am able to enter 'ddddfd' into any of these fields without an error being thrown.
    Cheers
    Aaron

  • zyko
    avatar
    Community Member
    64 posts

    Re: CurrencyField Format Link to this post

    subscribe...

    i wasn't even able to get the $ sign away globally... fe with €
    to get it on a 'format-field'-level would make things more right too..

    Last edited: 10 June 2008 at 8:23pm

  • Aaron
    Aaron's avatar
    Community Member
    63 posts

    Re: CurrencyField Format Link to this post

    Well, It either isn't possible or we're simply not going to get an answer (probably both). I've found nada in my digging.

    I will be using a decimal field and hardcoding the currency format into it. (And definately not trusting silverstripe to take care of calculations - I will be POST-ing to standalone PHP pages for that.

    Last edited: 13 June 2008 at 10:56am

  • willr
    avatar
    Core Development Team
    1263 posts
    3 SilverStripe Sites 2 SilverStripe Themes

    Re: CurrencyField Format Link to this post

    Line 16 - 23 of Currency.php

       function Nice() {
          return '$' . number_format($this->value, 2);
       }
       
       function Whole() {
          return '$' . number_format($this->value, 0);
       }

    Try changing the $. I would assume this is where it is coming from!. You might like to abstract this out and submit is as a patch. It shouldnt be hardcoded in the core I would have thought

  • Double-A-Ron
    avatar
    Community Member
    149 posts
    1 SilverStripe Site

    Re: CurrencyField Format Link to this post

    Thanks Willr,

    I'll look into that but I'm outta time on this project now.

    I will look at the patch submission process, as ideally, I think this currency symbol is best tied to each field.

    Do you see a problem with passing the symbol as an argument? I'm a bit fresh in terms of what can be passed. I know that you can't pass variables as arguments.

    e.g.


    function Nice($symbol = '$') {
    return $symbol . number_format($this->value, 2);
    }

    function Whole($symbol = '$') {
    return $symbol . number_format($this->value, 0);
    }

  • willr
    avatar
    Core Development Team
    1263 posts
    3 SilverStripe Sites 2 SilverStripe Themes

    Re: CurrencyField Format Link to this post

    hmm makes it interesting to have 2 different symbols on the same page. Passing it as an argument with a default might be the best / easiest way!

  • Ingo
    avatar
    Core Development Team
    379 posts

    Re: CurrencyField Format Link to this post

    localization of dates/currencies etc is not implemented yet for silverstripe,
    but its pretty easy to subclass e.g. CurrencyField to return different formats for Nice() etc

    for validation, we're currently migrating to the jquery validate plugin, which should provide more solid (and already localized) clientside support.

    903 views
go to top Reply

Currently Online:

Brian, Craig, Hamish, Apophenian

Welcome to our latest member: bagherozzo21