keystonejs/keystone-classic

Numeral is not unformatted after a format is called

Open

#4060 opened on Mar 3, 2017

View on GitHub
 (0 comments) (0 reactions) (0 assignees)JavaScript (14,656 stars) (2,288 forks)batch import
bughelp wanted

Description

Steps to reproduce the behavior

Call .format() on a money field with a locale set, such as en-gb, then call numeral.format() without defining a locale anywhere else within keystone.

Expected behavior

The new call will be agnostic of the first call occurring, and have no locale.

Actual behavior

The locale is not unset, and all future calls to numeral.format() will use the defined locale, until the locale is reset.

Possible solutions

Move away from numeral, probably to using toLocaleString(). Refactor code so our locale is reset to the default numeral locale ('en') after we have formatted anything. If we take this path, we need to also set a default for all money fields.

Additionally, this holds an impact on how the Number field operates if there is a Money field, and a Money field that sets currency is going to cause numbers to be formatted using the locale unless it is reset afterwards.

I'd also suggest perhaps deprecating the 'money' field. It holds very little functionality, and is likely better to just use the number field for this.

Contributor guide