keystonejs/keystone-classic

Numeral is not unformatted after a format is called

Open

#4060 aperta il 3 mar 2017

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)JavaScript (2288 fork)batch import
bughelp wanted

Metriche repository

Star
 (14.656 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor