I am facing an issue where the number being typed into a text field does not have commas separating the thousands
For example, if the user types 500000, it displays as 500000 instead of 500,000
This issue is present in the models section of the code:
so_tien=models.PositiveIntegerField(max_length=50)
And also in the forms section:
so_tien=forms.IntegerField(label="Số tiền",widget=forms.NumberInput(attrs={"class":"form-control",'onfocusout': 'numberWithCommas()',}),required=False)
Furthermore, it affects the template file section:
<div class="col-md-4" id="sotien" style="display:none">{{ form.so_tien}}</div>
The JavaScript code `numberWithCommas` in the template file attempts to resolve this issue:
<script language="JavaScript">
function numberWithCommas(){
var input = document.getElementById('{{ form.so_tien.id_for_label}}');
input.value = parseInt(input.value).toLocaleString()
}
Thank you for taking the time to read this information