Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

validate() change in 3.2?


Go to End


2 Posts   967 Views

Avatar
muskie9

Community Member, 24 Posts

27 December 2015 at 2:24pm

Edited: 27/12/2015 2:26pm

I've used

validate()
in the past. I have a page type where I have
'StartDate' => 'Date'
as a db field. I have the following validation method:

    /**
     * @return ValidationResult
     */
    public function validate()
    {
        $result = parent::validate();

        if ($this->ID > 0 && !$this->StartDate) {
            $result->error('Start Date is required');
        }

        return $result;
    }

I can create the page as

$this->ID > 0
works properly, but then after the initial creation, when
StartDate
is a valid date (using the date popup of the DateField) and I attempt to save the page, it throws the validation exception. Has anyone else come across this type of behavior?

Thanks

Avatar
LoFonz

Community Member, 12 Posts

13 January 2016 at 12:23pm

Did you try with $this-> StartDate(); ?

Btw if this is a required filed in the getCMSFIelds() function, why don't you use the native getCMSValidator() to set your fields as required?