4

I'm trying to add thousand separators to my inputs, how can I do it? I tried to use Laravel\Nova\Fields\Currency in my fields() method, but it doesn't help. It still shows value in the input like:

100000

And I want to show it like:

100,000

How can I achieve it in Laravel Nova?

public function fields(Request $request)
{
    $fields = [];

    ...
    $fields[] = Currency::make(__('Price'), 'price');

    return $fields;
}
Raptor
  • 53,206
  • 45
  • 230
  • 366
SakuragiRokurota
  • 185
  • 1
  • 3
  • 12
  • where you want to show the separator? – Giacomo M Aug 19 '19 at 07:03
  • In inputs in my form to display it to the user in clear format when he will typing the price, then save the value without those separators. – SakuragiRokurota Aug 19 '19 at 07:05
  • Possible duplicate of [How to print a number with commas as thousands separators in JavaScript](https://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript) – nice_dev Aug 19 '19 at 07:10
  • if you wanna do that you can't do with PHP, you need a client side language like javascript – Giacomo M Aug 19 '19 at 07:25
  • I know it's a frontend problem, however I thought there is some package or solution exists dedicated for Laravel Nova. Cause in Laravel Nova it's not that easy to add custom javascript code to your project and I don't want to make it more complicated than it's currently is. – SakuragiRokurota Aug 19 '19 at 08:27
  • @SakuragiRokurota What is your Nova version? – Saumini Navaratnam Aug 20 '19 at 04:41

2 Answers2

2

use number_format() doc or money_format() doc (won't work on windows), which were available in php.

  • I need solution for Laravel Nova, I tried to do it with money_format(), but it didn't work. Maybe there exists solution or package for nova that could be helpful. Or someone experience similar issue, cause in nova it's not that easy to add some javascript code that would be working. – SakuragiRokurota Aug 19 '19 at 08:26
  • 1
    @SakuragiRokurota In the `money_format()` doc it is saying it won't work in windows. So if you were using windows try to use `number_format()`. I don't know about nova. But generally if it supports in language like php, it should also support in the frameworks which is built on top of it. – Sravanth Pujari Aug 19 '19 at 08:47
1

You can use this package, I just about to write it recently: https://novapackages.com/packages/lathanhvien/nova-text-currency

protoproto
  • 2,081
  • 1
  • 13
  • 13