Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field Validation and Input Mask #6

Open
ingodjango opened this issue Feb 21, 2014 · 4 comments
Open

Field Validation and Input Mask #6

ingodjango opened this issue Feb 21, 2014 · 4 comments

Comments

@ingodjango
Copy link

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.

@michaelkuty
Copy link

is any suggestion in this topic ?

@ingodjango
Copy link
Author

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.

@michaelkuty
Copy link

yes, i try some with clean method but without positive results
my guess is that problem is javascript

@ingodjango
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants