I am having problem creating a number form control.
The generated control has input restriction to only numeric digits and “.” (decimal point).
However, I want to input number with thousand separator (‘,’).
I have tried using javascript to edit entered text, however, the input box does not allow the comma (thousand separator).
$('.numeric').on('input', function () {
// Get the current value of the input
let value = $(this).val();
//alert('test numeric');
// Remove any non-digit characters from the input
value = value.replace(/[^\d]/g, '');
// Add thousand separators to the input value
value = Number(value).toLocaleString(undefined, {groupingSeparator: '-'});
// Set the formatted value back into the input
$(this).val(value);
});
I also tried adding custom local to config file but this does not help:
'Number' => [
'locale' => 'en-US',
'thousandSeparator' => ','
],
I also tried to change locale of that form input but also does not work:
echo $this->Form->control('est_total', ['label' => 'Cost Estimation', 'empty' => true, 'type' => 'text' ,'step' => 'any', 'locale' => 'en-US', 'templateVars' => ['extra_class' => 'numeric', 'ctnClass' => 'col-md-3']]);
I also tried to create that form control using HTML code, not the CakePHP form helper, but also did not work.
Can someone help me with that. Thanks you very much