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.

Data Model Questions /

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

[SOLVED] Custom validation on DataObject / ModelAdmin


Go to End


11 Posts   17392 Views

Avatar
Hattori

Community Member, 20 Posts

4 July 2014 at 7:36am

Never mind, it works fine after i have updated to 3.1.5 =))

Avatar
code_dave

Community Member, 1 Post

7 November 2015 at 3:44am

Hi All!
I just wanted to reuse this post since I have quite similar problem ant it could not be solved with the proposed approaches :-/
I am using SS V 3.1.13.

I have a simple DataObject that has a Varchar field "name". This attribute should be used only once (is unique) across the system.
I have used AjaxUniqueTextField but this construct is not working properly :-/ If saving an existing alraedy persisted DO it says the "name" is not unique (but it does!). In the AjaxUniqueTextField there is one important Thing missing - exclusion of all entries with ID of the current Instance if already persisted.

I tried to implement the proper validation in an inherited Class of RequiredFieldsValidator, but unfortunately I need the ID of the Record being validated, to build correct DB Query - but I can't find it in the $_REQUEST var anymore like in the previous answers.

Is there any other Pattern to implement Unique Value Validation?
Or how can I access the DO ID in the Validator?

Thanks in advance!

BR
code_dave

Avatar
Abdou

Community Member, 3 Posts

26 November 2015 at 11:28am

Edited: 26/11/2015 11:30am

just insert

   public function getValidator() {
                  
                  // Answers a validator for the record.
                  
                     return new RequiredFields('SystemName','Name');
                  
                  }

in your dataobject

Go to Top