Jump to content

format number in admin


a.masca
 Share

Recommended Posts

Hello and thank you for the great job that all of you do every day on this great project!!!

 

I have a little question:

is possible to format the field float or decimal in this way: from 1000000.56 to 1.000.000,56 in repeater and repeater matrix?

 

Thank you very much

Andrea

 

1174908187_Schermata2018-10-04alle18_40_00.png.85c2ce36eecd77955b49c8cad48a3d66.png

Link to comment
Share on other sites

Just for display in the repeater label? That can be done with a little hook in site/ready.php:

wire()->addHookAfter('InputfieldRepeater::renderRepeaterLabel', function (HookEvent $e) {
	$label = $e->return;
	$page = $e->arguments('page');
	
	$label = preg_replace_callback('/\\[([a-zA-Z0-9_]+)\\]/', function($match) use($page) {
		return number_format($page->{$match[1]}, 2, ',', '.');
	}, $label);
	
	$e->return = $label;
});

This looks for a field name between square brackets (something like "[price]" in "#n: {title} - {item} - [price]") in the label and replaces it with the formatted value of that field.

  • Like 8
Link to comment
Share on other sites

  • 4 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...