Currency Validation
Currency Validation
I've loooked around but don't see a validator that validates currency when a person enters data in the field. I see a couple options for formatting a number in table view with a $, but not input validation.
I tried:
Field::inst( 'price' )->validator( 'Validate::numeric' ),
This works for input with an amount like 79.83 but in table view it renders (expectedly) without a $
I found this:
{ data: "price", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) },
but in table view it renders as a rounded whole number:
$80
This will confuse the administrator. How do I get it to render as $79.83?
This question has an accepted answers - jump to answer
Answers
In your second code extract, the third option for $.fn.dataTable.render.number species the decimal places - yours is set to
0
. If you set that to2
, you should be good to go.Colin