Jump to content

Can I have number fields with commas?

fields commas number

  • Please log in to reply
2 replies to this topic

#1 HumbleMonk



  • Members
  • PipPip
  • 25 posts

Posted 01 January 2013 - 05:02 PM

I use a lot of number fields in my application. It is hard to read large numbers at a glance without some type of indicator, e.g. compare 1345600 to 1,345,600. The grocery crud number filter prevents commas from being entered into the field.

Is there some way to allow commas to be entered in the number field but stripped before the item is saved? I've poked around but can't figure out where GroceryCrud prevents anything but numbers from being entered.

Ideally the flow would be something like this:

Read number field from database
Automatically populate with commas
Automatically adjust commas if field is edited
On save, strip commas and then submit

#2 Alvin Lesmana

Alvin Lesmana


  • Members
  • Pip
  • 1 posts

Posted 02 January 2013 - 08:12 AM

Put this on your controller


and add this function :

function format_num($value, $row){
return number_format($value, 0);


#3 HumbleMonk



  • Members
  • PipPip
  • 25 posts

Posted 03 January 2013 - 11:08 PM

Thank you for the answer.

That results in a formatted field, like I want, however it is not editable. I need this field to be editable.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users