﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30126	Incorrect validation of forms.DecimalField	Roman Paranichev	nobody	"Steps to reproduce:
1. create html form

{{{
<form action=""/payment/"">
<input type=""number"" step=""0.01"" name=""amount"" value=""0.02"" required>
<input type=""submit"" value=""Submit"">
</form>
}}}

2. create django-form for validation:

{{{
from django import forms

class CreatePaymentForm(forms.Form):
    amount = forms.DecimalField(min_value=0.02, max_digits=12, decimal_places=2)
}}}

3. Try to validate from in a view class:

{{{
import json
from django.http import HttpResponse
from django.views.generic import View
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
from api.forms import CreatePaymentForm

@method_decorator(login_required, name='dispatch')
@method_decorator(csrf_exempt, name='dispatch')
class PaymentView(View):

    def post(self, request):
        form = CreatePaymentForm(request.POST)
        if form.is_valid():
              pass
        print(""post: %s, errors: %s"" % (request.POST, form.errors))
        return HttpResponse(json.dumps({'errors': form.errors}), status=400)
}}}

The output will be:
post: <QueryDict: {'amount': ['0.02']}>, errors: <ul class=""errorlist""><li>amount<ul class=""errorlist""><li>Ensure this value is greater than or equal to 0.02.</li></ul></li></ul>
"	Bug	closed	Forms	2.1	Normal	invalid			Unreviewed	0	0	0	0	0	0
