17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1956 Views |
-
getCMSFields_forPopup validation

9 July 2008 at 5:15pm
I have a custom page which has a has_many relationship to a dataobject.
These objects are displayed in a getCMSFields HasManyComplexTableField.
I am running a function within onBeforeWrite() in the dataobject's class in order to validate a value which is entered before saving it to the DB. However if the value is not valid I have no way to notify the user. If I attempt to return any value from the onBeforeWrite function then it just hangs with the "saving..." button spinning.
How can I send a meaningful response back to the user?
-
Re: getCMSFields_forPopup validation

10 July 2008 at 2:47am
I don't have an exact answer, but maybe you can use these things:
- LeftAndMain::ForceReload();
(see http://api.silverstripe.com/cms/core/LeftAndMain.html, look at the comment at the bottom)- FormResponse: http://api.silverstripe.com/forms/core/FormResponse.html, which will output a message in the ajax way...
Hope this can help somehow...
-
Re: getCMSFields_forPopup validation

10 July 2008 at 8:45am Last edited: 10 July 2008 9:26am
Thanks Dio5.. tried using FormResponse in the onBeforeWrite function but this doesn't return any value to the user. Perhaps I need to be returning values from elsewhere..
-
Re: getCMSFields_forPopup validation

10 July 2008 at 10:56am
Ok, so here's my work around. Was the only way I could see to get information back to the user.
Basically
1) create an extra field on your dataObject called Response
2) Add $fields->push( new ReadonlyField( 'Response', 'Response' ) ); to your getCMSFields_forPopup function.
3) Then based on your response you want to send set it in onBeforeWrite with $this->Response = "Error - blah blah";This solution, although not ideal, works. The main problem is that the record is still saved. In my case this is not too much of a problem as I use the response field to filter whether or not to show an item on the front end of the CMS.
And since the popup box stays open it gives the user another chance to correct the problem and then save again.
| 1956 Views | ||
|
Page:
1
|
Go to Top |


