Fixed null pointer access on validating booking without dogs or options

This commit is contained in:
jordi fita mas 2024-02-13 17:05:19 +01:00
parent 0f76351ae9
commit 77a3f78176
1 changed files with 5 additions and 5 deletions

View File

@ -226,11 +226,11 @@ func (f *bookingForm) Valid(ctx context.Context, conn *database.Conn, l *locale.
v.CheckSelectedOptions(f.CampsiteType, l.GettextNoop("Selected campsite type is not valid."))
f.Dates.Valid(v, l)
f.Guests.Valid(v, l)
f.Options.Valid(v, l)
if err := f.Customer.Valid(ctx, conn, v, l); err != nil {
return false, err
}
if f.Options != nil {
if err := f.Customer.Valid(ctx, conn, v, l); err != nil {
return false, err
}
f.Options.Valid(v, l)
}
return v.AllOK, nil
}
@ -387,7 +387,7 @@ func (f *bookingGuestFields) Valid(v *form.Validator, l *locale.Locale) {
v.CheckMinInteger(f.NumberChildren, 0, l.GettextNoop("Number of children can not be negative."))
}
}
if v.CheckRequired(f.NumberDogs, l.GettextNoop("Number of dogs can not be empty")) {
if f.NumberDogs != nil && v.CheckRequired(f.NumberDogs, l.GettextNoop("Number of dogs can not be empty")) {
if v.CheckValidInteger(f.NumberDogs, l.GettextNoop("Number of dogs must be an integer.")) {
v.CheckMinInteger(f.NumberDogs, 0, l.GettextNoop("Number of dogs can not be negative."))
}