ValidateValue implements [Field.ValidateValue] interface method.
(ctx context.Context, app App, record *Record)
| 120 | |
| 121 | // ValidateValue implements [Field.ValidateValue] interface method. |
| 122 | func (f *DateField) ValidateValue(ctx context.Context, app App, record *Record) error { |
| 123 | val, ok := record.GetRaw(f.Name).(types.DateTime) |
| 124 | if !ok { |
| 125 | return validators.ErrUnsupportedValueType |
| 126 | } |
| 127 | |
| 128 | if val.IsZero() { |
| 129 | if f.Required { |
| 130 | return validation.ErrRequired |
| 131 | } |
| 132 | return nil // nothing to check |
| 133 | } |
| 134 | |
| 135 | if !f.Min.IsZero() { |
| 136 | if err := validation.Min(f.Min.Time()).Validate(val.Time()); err != nil { |
| 137 | return err |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if !f.Max.IsZero() { |
| 142 | if err := validation.Max(f.Max.Time()).Validate(val.Time()); err != nil { |
| 143 | return err |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return nil |
| 148 | } |
| 149 | |
| 150 | // ValidateSettings implements [Field.ValidateSettings] interface method. |
| 151 | func (f *DateField) ValidateSettings(ctx context.Context, app App, collection *Collection) error { |