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.

Data Model Questions /

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

DataObject Validation on AddForm or EditForm CMS

Go to End

4 Posts   3460 Views


Community Member, 165 Posts

9 September 2009 at 8:37am

I have a DataObject that can be added and edited in a ModelAdmin. I have a particular field in the CMS that must have a number entered.

I tried using:

public function getCMSValidator() {
return new RequiredFields('FirstName', 'Surname', 'BestNotesID');

But when I submit the EditForm without the number I just get a blank grey area in the CMS_right area and this error message:

validationError('BestNotesID', '\"Best Notes ID\" is required.', 'required'); statusMessage('Validation failed', 'bad');Behaviour.addLoader(hideLoading);

So I can see that it does want to require the Fields but the behavior I get is unexpected. How do I handle the exception so that a nice error message is displayed and the EditForm is put back so the error can be corrected?

BLU42 Media

Community Member, 71 Posts

25 October 2009 at 10:54am

Did you ever get this figured out? I'm having the same issue with 2.3.3

In digging through the code, it looks like FormReponse is just dumping back plain html and it's not being recognized as javascript even though Director::is_ajax() is returning true.

Are there any js experts out there who want to take a crack at this?

Thanks in advance!


Forum Moderator, 801 Posts

2 November 2009 at 8:54am

The ModelAdmin form validation works a bit differently. It assumes the form to be returned as HTML, not JavaScript, and the validator interferes with that. I think you'll have to disable javascript validation for ModelAdmin forms (haven't tested though).

class MyModelAdmin extends ModelAdmin {
  function init() {

In a development branch, we've already changed this behaviour to be more consistent: The assumed response will always be HTML, and validation errors are displayed in the HTML response, and picked up by jQuery selectors for JavaScript usage.


Community Member, 165 Posts

11 December 2009 at 1:20pm

Still using SS 2.3.3 and getCMSValidator() and getting unexpected results. I put Validator::set_javascript_validation_handler('none'); in my ModelAdmin. What happens is that if I submit a form that doesn't validate the Main CMS window goes grey, but if I click the button to add the object again that is when I see the error messages next to the required fields which are now blank.

What I need it to do is just reload the add Form with the data still populated and the error messages showing so I can make the corrections and resubmit the add form.