Skip to content

Commit 882f141

Browse files
committed
fix validation
1 parent c87a476 commit 882f141

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

opendrift_leeway_webgui/leeway/forms.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
from django.contrib.auth import get_user_model
88
from django.contrib.auth.forms import UserCreationForm
99
from django.core.exceptions import ValidationError
10-
from django.forms import ChoiceField, DecimalField, ModelForm, Select, TextInput
10+
from django.forms import (
11+
ChoiceField,
12+
DecimalField,
13+
FloatField,
14+
ModelForm,
15+
Select,
16+
TextInput,
17+
)
1118

1219
from .models import LeewaySimulation, Webhook
1320

@@ -43,6 +50,12 @@ class LeewaySimulationForm(ModelForm):
4350
decimal value in the ``clean_latitude`` / ``clean_longitude`` methods.
4451
"""
4552

53+
# Override model FloatFields as not-required so that returning None from
54+
# clean_latitude / clean_longitude (when a sub-field already reported an
55+
# error) does not produce a duplicate "This field is required." message.
56+
latitude = FloatField(required=False)
57+
longitude = FloatField(required=False)
58+
4659
#: Direction choices for latitude
4760
LAT_DIR_CHOICES = [("N", "N"), ("S", "S")]
4861
#: Direction choices for longitude

0 commit comments

Comments
 (0)