typical icon indicating copy to clipboard operation
typical copied to clipboard

Custom validation feature request

Open jae-lee opened this issue 5 years ago • 2 comments

Description

Would like to see a feature to implement custom validations that could span multiple fields. For example:

Let's say you had a vacation start date and vacation end date field. Vacation start date should be before vacation end date.

jae-lee avatar Feb 07 '20 18:02 jae-lee

@jae-lee maybe I misunderstand, but can you use post_init to validate dependent fields?

import typic
from datetime import datetime


@typic.klass
class DateCheck:
    start: datetime
    end: datetime

    def __post_init__(self):
        if self.start > self.end:
            raise ValueError("Start date have to be before end date.")

kfollesdal avatar Mar 20 '20 16:03 kfollesdal

I agree this will be an awesome feature. Many times you want a deeper validation beyond type checks which you can only implement.

What is the status of this issue?

MVrachev avatar Mar 12 '21 16:03 MVrachev