Field Validation and Input Mask
Hi, I'm not sure if this is the right place to ask but since I did not know where else to post it, here's my problem. I use django-input-mask in a django project on a admin site with a lot of fields. What I do is:
class FinancialKeyFiguresForm(forms.ModelForm):
class Meta: model = models.FinancialKeyFigures
widgets = {
'company_sales': DecimalInputMask(max_digits=18, decimal_places=2)
, 'group_sales': DecimalInputMask(max_digits=18, decimal_places=2)
, 'external_sales': DecimalInputMask(max_digits=18, decimal_places=2)
, 'percentage_of_exports': DecimalInputMask(max_digits=18, decimal_places=2)
, 'profit_before_taxes': DecimalInputMask(max_digits=18, decimal_places=2)
, 'profit_after_taxes': DecimalInputMask(max_digits=18, decimal_places=2)
}
When I try now editing on the admin page of my project to save what I have put in then all fields the above where a mask is applied to are throwing a validation error with the message that they need a number. What am I doing wrong?
Thanks.
is any suggestion in this topic ?
If your asking me? Then first of all it's a question, if I'm doing something wrong. But before I bother people with good ideas I want to unterstand if I'm making a mistake.
yes, i try some with clean method but without positive results my guess is that problem is javascript
okay, that's what I also tried first, but since the mask is still in the cleaned data there is already an error applied to the field.
Next idea was that I tried to unset the mask first with overriding the submit_line.html template and force the submit buttons to do myscript to unset the mask before sending it back, but this also didn't work.
Now, with more or less the sam approach I replaces the django-input mask with a different lib, have written my own widgets, set the mask back before sending it and fix the decimal in the widget in the value_from_datadict method. I guess this can be solved in a better way with managing the masks wor in the widgets but I didn't came yet to that since it works good enough for now.